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

Commits on Mar 9, 2015

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    d2c0547 View commit details
  2. Merge pull request #2669 from bjfish/truffle_array_bsearch

    [Truffle] Adding Array#bsearch in array.rb.
    chrisseaton committed Mar 9, 2015
    Copy the full SHA
    03da281 View commit details
Showing with 43 additions and 13 deletions.
  1. +0 −13 spec/truffle/tags/core/array/bsearch_tags.txt
  2. +43 −0 truffle/src/main/ruby/core/rubinius/common/array.rb
13 changes: 0 additions & 13 deletions spec/truffle/tags/core/array/bsearch_tags.txt

This file was deleted.

43 changes: 43 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -348,6 +348,49 @@ def recursively_flatten(array, out, max_levels = -1)

private :recursively_flatten

def bsearch
return to_enum :bsearch unless block_given?

m = Rubinius::Mirror::Array.reflect self

tuple = m.tuple

min = start = m.start
max = total = start + m.total

last_true = nil
i = start + m.total / 2

while max >= min and i >= start and i < total
x = yield tuple.at(i)

return tuple.at(i) if x == 0

case x
when Numeric
if x > 0
min = i + 1
else
max = i - 1
end
when true
last_true = i
max = i - 1
when false, nil
min = i + 1
else
raise TypeError, "Array#bsearch block must return Numeric or boolean"
end

i = min + (max - min) / 2
end

return tuple.at(i) if max > min
return tuple.at(last_true) if last_true

nil
end

def flatten(level=-1)
level = Rubinius::Type.coerce_to_collection_index level
return self.dup if level == 0