Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8a86f38ea106
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 15eded4903e7
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Dec 15, 2016

  1. [Truffle] Simplify Array#drop.

    eregon committed Dec 15, 2016
    Copy the full SHA
    4be9103 View commit details
  2. Copy the full SHA
    15eded4 View commit details
Showing with 3 additions and 20 deletions.
  1. +3 −20 truffle/src/main/ruby/core/array.rb
23 changes: 3 additions & 20 deletions truffle/src/main/ruby/core/array.rb
Original file line number Diff line number Diff line change
@@ -412,7 +412,7 @@ def flatten(level=-1)
level = Rubinius::Type.coerce_to_collection_index level
return self.dup if level == 0

out = new_reserved size
out = [] # new_reserved size
recursively_flatten(self, out, level)
Rubinius::Type.infect(out, self)
out
@@ -424,7 +424,7 @@ def flatten!(level=-1)
level = Rubinius::Type.coerce_to_collection_index level
return nil if level == 0

out = new_reserved size
out = [] # new_reserved size
if recursively_flatten(self, out, level)
Truffle::Array.steal_storage(self, out)
return self
@@ -1039,12 +1039,10 @@ def drop(n)
n = Rubinius::Type.coerce_to_collection_index n
raise ArgumentError, "attempt to drop negative size" if n < 0

return [] if size == 0

new_size = size - n
return [] if new_size <= 0

new_range n, new_size
self[n..-1]
end

def sort_by!(&block)
@@ -1400,21 +1398,6 @@ def isort_block!(left, right, block)
end
private :isort_block!

# Truffle: what follows is our changes

def new_range(start, count)
ret = Array.new(count)

self[start..-1].each_with_index { |x, index| ret[index] = x }

ret
end

def new_reserved(count)
# TODO CS 6-Feb-15 do we want to reserve space or allow the runtime to optimise for us?
self.class.new(0 , nil)
end

def reverse!
Truffle.check_frozen
return self unless size > 1