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: 63fa292c738f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 41926825738d
Choose a head ref
  • 4 commits
  • 7 files changed
  • 2 contributors

Commits on Mar 11, 2015

  1. Copy the full SHA
    1537a15 View commit details
  2. Copy the full SHA
    a20fb48 View commit details
  3. 2
    Copy the full SHA
    9d1c01b View commit details
  4. Merge pull request #2681 from bjfish/truffle_array_combination

    [Truffle] Adding Array#combination to array.rb
    chrisseaton committed Mar 11, 2015
    Copy the full SHA
    4192682 View commit details
9 changes: 0 additions & 9 deletions spec/truffle/tags/core/array/combination_tags.txt

This file was deleted.

38 changes: 0 additions & 38 deletions spec/truffle/tags/core/array/fill_tags.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
fails:Array#fill returns self
fails:Array#fill is destructive
fails:Array#fill does not replicate the filler
fails:Array#fill replaces all elements in the array with the filler if not given a index nor a length
fails:Array#fill replaces all elements with the value of block (index given to block)
fails:Array#fill raises a RuntimeError on a frozen array
fails:Array#fill raises a RuntimeError on an empty frozen array
fails:Array#fill raises an ArgumentError if 4 or more arguments are passed when no block given
fails:Array#fill raises an ArgumentError if no argument passed and no block given
fails:Array#fill raises an ArgumentError if 3 or more arguments are passed when a block given
fails:Array#fill with (filler, index, length) replaces length elements beginning with the index with the filler if given an index and a length
fails:Array#fill with (filler, index, length) replaces length elements beginning with the index with the value of block
fails:Array#fill with (filler, index, length) replaces all elements after the index if given an index and no length
fails:Array#fill with (filler, index, length) replaces all elements after the index if given an index and nil as a length
fails:Array#fill with (filler, index, length) replaces the last (-n) elements if given an index n which is negative and no length
fails:Array#fill with (filler, index, length) replaces the last (-n) elements if given an index n which is negative and nil as a length
fails:Array#fill with (filler, index, length) makes no modifications if given an index greater than end and no length
fails:Array#fill with (filler, index, length) makes no modifications if given an index greater than end and nil as a length
fails:Array#fill with (filler, index, length) replaces length elements beginning with start index if given an index >= 0 and a length >= 0
fails:Array#fill with (filler, index, length) increases the Array size when necessary
fails:Array#fill with (filler, index, length) pads between the last element and the index with nil if given an index which is greater than size of the array
fails:Array#fill with (filler, index, length) replaces length elements beginning with the (-n)th if given an index n < 0 and a length > 0
fails:Array#fill with (filler, index, length) starts at 0 if the negative index is before the start of the array
fails:Array#fill with (filler, index, length) makes no modifications if the given length <= 0
fails:Array#fill with (filler, index, length) tries to convert the second and third arguments to Integers using #to_int
fails:Array#fill with (filler, index, length) raises a TypeError if the index is not numeric
fails:Array#fill with (filler, index, length) raises an ArgumentError or RangeError for too-large sizes
fails:Array#fill with (filler, range) replaces elements in range with object
fails:Array#fill with (filler, range) replaces all elements in range with the value of block
fails:Array#fill with (filler, range) increases the Array size when necessary
fails:Array#fill with (filler, range) raises a TypeError with range and length argument
fails:Array#fill with (filler, range) replaces elements between the (-m)th to the last and the (n+1)th from the first if given an range m..n where m < 0 and n >= 0
fails:Array#fill with (filler, range) replaces elements between the (-m)th and (-n)th to the last if given an range m..n where m < 0 and n < 0
fails:Array#fill with (filler, range) replaces elements between the (m+1)th from the first and (-n)th to the last if given an range m..n where m >= 0 and n < 0
fails:Array#fill with (filler, range) makes no modifications if given an range which implies a section of zero width
fails:Array#fill with (filler, range) makes no modifications if given an range which implies a section of negative width
fails:Array#fill with (filler, range) raises an exception if some of the given range lies before the first of the array
fails:Array#fill with (filler, range) tries to convert the start and end of the passed range to Integers using #to_int
fails:Array#fill with (filler, range) raises a TypeError if the start or end of the passed range is not numeric
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/array/reverse_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
fails:Array#reverse! reverses the elements in place
fails:Array#reverse! properly handles recursive arrays
fails:Array#reverse! raises a RuntimeError on a frozen array
Empty file.
6 changes: 6 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/tuple.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,10 @@ module Rubinius

class Tuple < Array

def self.pattern(num, val)
Tuple.new(num, val)
end

def copy_from(other, start, length, dest)
# TODO CS 6-Feb-15 use higher level indexing when it works
length.times do |n|
@@ -30,4 +34,6 @@ def swap(a, b)
self[b] = temp
end

alias_method :put, :[]=

end
133 changes: 133 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -405,6 +405,43 @@ def bsearch
nil
end


def combination(num)
num = Rubinius::Type.coerce_to_collection_index num
return to_enum(:combination, num) unless block_given?

if num == 0
yield []
elsif num == 1
each do |i|
yield [i]
end
elsif num == size
yield self.dup
elsif num >= 0 && num < size
stack = Rubinius::Tuple.pattern num + 1, 0
chosen = Rubinius::Tuple.new num
lev = 0
done = false
stack[0] = -1
until done
chosen[lev] = self.at(stack[lev+1])
while lev < num - 1
lev += 1
chosen[lev] = self.at(stack[lev+1] = stack[lev] + 1)
end
yield chosen.to_a
lev += 1
begin
done = lev == 0
stack[lev] += 1
lev -= 1
end while stack[lev+1] + num == size + lev + 1
end
end
self
end

def cycle(n=nil)
return to_enum(:cycle, n) unless block_given?
return nil if empty?
@@ -437,6 +474,83 @@ def each_index
self
end

def fill(a=undefined, b=undefined, c=undefined)
Rubinius.check_frozen

if block_given?
unless undefined.equal?(c)
raise ArgumentError, "wrong number of arguments"
end
one, two = a, b
else
if undefined.equal?(a)
raise ArgumentError, "wrong number of arguments"
end
obj, one, two = a, b, c
end

if one.kind_of? Range
raise TypeError, "length invalid with range" unless undefined.equal?(two)

left = Rubinius::Type.coerce_to_collection_length one.begin
left += size if left < 0
raise RangeError, "#{one.inspect} out of range" if left < 0

right = Rubinius::Type.coerce_to_collection_length one.end
right += size if right < 0
right += 1 unless one.exclude_end?
return self if right <= left # Nothing to modify

elsif one and !undefined.equal?(one)
left = Rubinius::Type.coerce_to_collection_length one
left += size if left < 0
left = 0 if left < 0

if two and !undefined.equal?(two)
begin
right = Rubinius::Type.coerce_to_collection_length two
rescue TypeError
raise ArgumentError, "second argument must be a Fixnum"
end

return self if right == 0
right += left
else
right = size
end
else
left = 0
right = size
end

total = @start + right

if right > @total
#reallocate total # I don't believe this is necessary since Tuple isn't used internally
@total = right
end

# Must be after the potential call to reallocate, since
# reallocate might change @tuple
tuple = @tuple

i = @start + left

if block_given?
while i < total
tuple.put i, yield(i-@start)
i += 1
end
else
while i < total
tuple.put i, obj
i += 1
end
end

self
end

def flatten(level=-1)
level = Rubinius::Type.coerce_to_collection_index level
return self.dup if level == 0
@@ -512,6 +626,25 @@ def compile_repeated_permutations(combination_size, place, index, &block)

private :compile_repeated_permutations

def reverse
Array.new dup.reverse!
end

def reverse!
Rubinius.check_frozen
return self unless @total > 1

i = 0
while i < self.length / 2
temp = self[i]
self[i] = self[self.length - i - 1]
self[self.length - i - 1] = temp
i += 1
end

return self
end

def reverse_each
return to_enum(:reverse_each) unless block_given?

11 changes: 0 additions & 11 deletions truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -110,17 +110,6 @@ def append(other)
end
end

class Array

def reverse
res = []

each { |x| res.unshift x }

res
end
end

module Kernel
def inspect
ivars = instance_variables