From d81bbb924d926276073b6853c0ac9a3732b77d79 Mon Sep 17 00:00:00 2001 From: Lillian Zhang Date: Wed, 25 Nov 2020 13:01:35 -0500 Subject: [PATCH] Use Primitive/nil instead of beginless? and endless? --- src/main/ruby/truffleruby/core/range.rb | 22 +++++++++---------- .../core/truffle/range_operations.rb | 10 +-------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main/ruby/truffleruby/core/range.rb b/src/main/ruby/truffleruby/core/range.rb index 5d7b2aa45782..1fbd6b0db5ea 100644 --- a/src/main/ruby/truffleruby/core/range.rb +++ b/src/main/ruby/truffleruby/core/range.rb @@ -99,8 +99,8 @@ def bsearch(&block) end private def bsearch_float(&block) - normalized_begin = Truffle::RangeOperations.beginless?(self) ? -Float::INFINITY : self.begin.to_f - normalized_end = Truffle::RangeOperations.endless?(self) ? Float::INFINITY : self.end.to_f + normalized_begin = Primitive.nil?(self.begin) ? -Float::INFINITY : self.begin.to_f + normalized_end = Primitive.nil?(self.end) ? Float::INFINITY : self.end.to_f normalized_end = normalized_end.prev_float if self.exclude_end? min = normalized_begin max = normalized_end @@ -263,12 +263,10 @@ def bsearch(&block) end def count(item = undefined) - if Truffle::RangeOperations.beginless?(self) || Truffle::RangeOperations.endless?(self) + if Primitive.nil?(self.begin) || Primitive.nil?(self.end) return Float::INFINITY unless block_given? || !Primitive.undefined?(item) end - p "count for here" - super end @@ -386,15 +384,15 @@ def inspect end def last(n=undefined) - raise RangeError, 'cannot get the last element of endless range' if Truffle::RangeOperations.endless?(self) + raise RangeError, 'cannot get the last element of endless range' if Primitive.nil? self.end return self.end if Primitive.undefined? n to_a.last(n) end def max - raise RangeError, 'cannot get the maximum of endless range' if Truffle::RangeOperations.endless?(self) - if Truffle::RangeOperations.beginless?(self) + raise RangeError, 'cannot get the maximum of endless range' if Primitive.nil? self.end + if Primitive.nil? self.begin raise RangeError, 'cannot get the maximum of beginless range with custom comparison method' if block_given? return exclude_end? ? self.end - 1 : self.end end @@ -415,8 +413,8 @@ def max end def min - raise RangeError, 'cannot get the minimum of beginless range' if Truffle::RangeOperations.beginless?(self) - if Truffle::RangeOperations.endless?(self) + raise RangeError, 'cannot get the minimum of beginless range' if Primitive.nil? self.begin + if Primitive.nil? self.end raise RangeError, 'cannot get the minimum of endless range with custom comparison method' if block_given? return self.begin end @@ -519,9 +517,9 @@ def cover?(value) end def size - return Float::INFINITY if Truffle::RangeOperations.beginless?(self) + return Float::INFINITY if Primitive.nil? self.begin return nil unless self.begin.kind_of?(Numeric) - return Float::INFINITY if Truffle::RangeOperations.endless?(self) + return Float::INFINITY if Primitive.nil? self.end delta = self.end - self.begin return 0 if delta < 0 diff --git a/src/main/ruby/truffleruby/core/truffle/range_operations.rb b/src/main/ruby/truffleruby/core/truffle/range_operations.rb index 6cde9bcbd561..deb90c204da4 100644 --- a/src/main/ruby/truffleruby/core/truffle/range_operations.rb +++ b/src/main/ruby/truffleruby/core/truffle/range_operations.rb @@ -113,7 +113,7 @@ def self.cover?(range, value) return false unless beg_compare if Comparable.compare_int(beg_compare) <= 0 - return true if endless?(range) + return true if Primitive.nil? range.end end_compare = (value <=> range.end) if range.exclude_end? @@ -126,14 +126,6 @@ def self.cover?(range, value) false end - def self.beginless?(range) - Primitive.nil? range.begin - end - - def self.endless?(range) - Primitive.nil? range.end - end - # MRI: r_less def self.range_less(a, b) compare = a <=> b