File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -165,9 +165,7 @@ def ==(other)
165
165
# negative indexes refer to the end of array
166
166
start += len if start < 0
167
167
stop += len if stop < 0
168
-
169
- stop += 1 unless seq . exclude_end?
170
- diff = stop - start
168
+ diff = stop - start + ( seq . exclude_end? ? 0 : 1 )
171
169
172
170
is_out_of_bound = start < 0 || start > len
173
171
@@ -184,12 +182,15 @@ def ==(other)
184
182
return self [ start , diff ] if step == 1 # step == 1 is a simple slice
185
183
186
184
# optimize when no step will be done and only start element is returned
187
- return self [ start , 1 ] if ( step > 0 && step > diff ) || ( step < 0 && step < -diff )
185
+ return self [ start , 1 ] if ( step > 0 && step > diff )
186
+ return self [ stop , 1 ] if ( step < 0 && step < -diff )
188
187
189
188
ustep = step . abs
190
189
nlen = ( diff + ustep - 1 ) / ustep
191
190
i = 0
192
- j = start + ( step > 0 ? 0 : diff - 1 ) # because we inverted negative step ranges
191
+ j = start
192
+ j += diff - ( seq . exclude_end? ? 0 : 1 ) if step < 0 # because we inverted negative step ranges
193
+
193
194
res = Array . new ( nlen )
194
195
195
196
while i < nlen
You can’t perform that action at this time.
0 commit comments