summaryrefslogtreecommitdiff
path: root/numeric.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2024-11-12 20:35:38 -0800
committerTakashi Kokubun <[email protected]>2024-11-13 12:27:26 -0800
commitd57d85548f92143054d90af11b00a25e0239bce0 (patch)
tree8b2ccad5899c25f8a2bb103751eac6fff8f79955 /numeric.rb
parentbeafae97505f9def3967e958bb1f7bc7fd7b9a7a (diff)
Move Integer#downto to Ruby
Co-Authored-By: Aaron Patterson <[email protected]>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12074
Diffstat (limited to 'numeric.rb')
-rw-r--r--numeric.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/numeric.rb b/numeric.rb
index 89c402e9e1..9b134a35ae 100644
--- a/numeric.rb
+++ b/numeric.rb
@@ -321,6 +321,26 @@ class Integer
def denominator
1
end
+
+ with_yjit do
+ if Primitive.rb_builtin_basic_definition_p(:downto)
+ undef :downto
+
+ def downto(to) # :nodoc:
+ Primitive.attr! :inline_block, :c_trace
+
+ unless defined?(yield)
+ return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 1, &to, int_downto_size)'
+ end
+
+ from = self
+ while from >= to
+ yield from
+ from = from.pred
+ end
+ end
+ end
+ end
end
class Float