Skip to content

Commit

Permalink
Ruby 2.7: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gogainda committed Dec 16, 2020
1 parent a260037 commit f427326
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/main/ruby/truffleruby/core/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
Object.deprecate_constant :Fixnum, :Bignum

class Integer < Numeric
FIXNUM_MAX = 0x3fffffff

# Have a copy in Integer of the Numeric version, as MRI does
alias_method :remainder, :remainder
Expand Down Expand Up @@ -81,35 +80,27 @@ def [](index, len = undefined)
end

private def handle_range(range)
validate_range(range)
raise FloatDomainError , 'Infinity' if range.begin == Float::INFINITY || range.end == Float::INFINITY
raise FloatDomainError , '-Infinity' if range.begin == -Float::INFINITY || range.end == -Float::INFINITY

if !Primitive.nil?(range.begin) && !Primitive.nil?(range.end)
len = range.end - range.begin
len += 1 if !range.exclude_end?
num = self >> range.begin
mask = mask(range, len)
mask = (1 << len) - 1

range.end < range.begin ? num : num & mask
elsif Primitive.nil? range.end

return self >> range.begin
else
result = self & mask(range, range.end)
raise ArgumentError, 'The beginless range for Integer#[] results in infinity' if result != 0 && range.end >= 0

0
end
end
len = range.end
len += 1 if !range.exclude_end?
mask = (1 << len) - 1

private def validate_range(index)
raise FloatDomainError , 'Infinity' if index.begin == Float::INFINITY || index.end == Float::INFINITY
raise FloatDomainError , '-Infinity' if index.begin == -Float::INFINITY || index.end == -Float::INFINITY
end
raise ArgumentError, 'The beginless range for Integer#[] results in infinity' if self & mask != 0 && range.end >= 0

private def mask(range, idx)
if range.exclude_end?
(1 << idx) - 1
else
(1 << (idx +1)) - 1
0
end
end

Expand Down

0 comments on commit f427326

Please sign in to comment.