Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2716: tuple optimization #2898

Merged
15 changes: 11 additions & 4 deletions eo-runtime/src/main/eo/org/eolang/tuple.eo
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@
index.lt 0
index.gte len
error "Given index is out of tuple bounds"
if.
index.lt (len.plus -1)
^.head.at index
^.tail
^.at-without-checks index

# Takes element from the tuple without checking i.
# i must be less than length and greater or equal 0.
# This is faster than at.
[i] > at-without-checks
levBagryansky marked this conversation as resolved.
Show resolved Hide resolved
i > idx!
levBagryansky marked this conversation as resolved.
Show resolved Hide resolved
if. > @
i.lt head.length
^.head.at-without-checks i
^.tail

# Create a new tuple with this element added to the end of it.
[x] > with
Expand Down
16 changes: 16 additions & 0 deletions eo-runtime/src/test/eo/org/eolang/tuple-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@
a.at 0
3

# Test
[] > at-without-checks-with-first-element
eq. > @
at.
* 100 101 102
0
100

# Test
[] > at-without-checks-with-last-element
eq. > @
at.
* 100 101 102
2
102

# Test.
[] > tuple-empty-fluent-with-indented-keyword
tuple
Expand Down
Loading