Skip to content

Commit

Permalink
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions truffle/src/main/ruby/core/array.rb
Original file line number Diff line number Diff line change
@@ -2130,24 +2130,22 @@ def bottom_up_merge_block(left, right, last, block)
def isort!(left, right)
i = left + 1

tup = self

while i < right
j = i

while j > left
jp = j - 1
el1 = tup.at(jp)
el2 = tup.at(j)
el1 = at(jp)
el2 = at(j)

unless cmp = (el1 <=> el2)
raise ArgumentError, "comparison of #{el1.inspect} with #{el2.inspect} failed (#{j})"
end

break unless cmp > 0

tup.put(j, el1)
tup.put(jp, el2)
self[j] = el1
self[jp] = el2

j = jp
end
@@ -2165,12 +2163,15 @@ def isort_block!(left, right, block)
j = i

while j > left
block_result = block.call(at(j - 1), at(j))
el1 = at(j - 1)
el2 = at(j)
block_result = block.call(el1, el2)

if block_result.nil?
raise ArgumentError, 'block returned nil'
elsif block_result > 0
swap(j, (j - 1))
self[j] = el1
self[j - 1] = el2
j -= 1
else
break

0 comments on commit b895022

Please sign in to comment.