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
14 changes: 10 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,16 @@
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 index validation.
# Here i must be an object that can be comparable with int using lt attribute.
levBagryansky marked this conversation as resolved.
Show resolved Hide resolved
[i] > at-without-checks
i > idx!
if. > @
idx.lt head.length
^.^.head.at.at-without-checks idx
^.^.tail

# Create a new tuple with this element added to the end of it.
[x] > with
Expand Down
18 changes: 18 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,24 @@
a.at 0
3

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

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

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