diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-09-07 10:57:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-07 10:57:52 -0700 |
commit | 5b5ae3d9e064e17e2a7d8d21d739fcc62ae1075c (patch) | |
tree | fde0e41fdd741cac9434969fa2d2a2df0d90e7e5 /numeric.c | |
parent | 4efcaf956e27df365a1cf9e0cbb8d9a68eeb6995 (diff) |
Rewrite Integer#times in Ruby (#8388)
Notes
Notes:
Merged-By: k0kubun <takashikkbn@gmail.com>
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 53 |
1 files changed, 0 insertions, 53 deletions
@@ -5652,58 +5652,6 @@ int_downto(VALUE from, VALUE to) return from; } -static VALUE -int_dotimes_size(VALUE num, VALUE args, VALUE eobj) -{ - if (FIXNUM_P(num)) { - if (NUM2LONG(num) <= 0) return INT2FIX(0); - } - else { - if (RTEST(rb_funcall(num, '<', 1, INT2FIX(0)))) return INT2FIX(0); - } - return num; -} - -/* - * call-seq: - * times {|i| ... } -> self - * times -> enumerator - * - * Calls the given block +self+ times with each integer in <tt>(0..self-1)</tt>: - * - * a = [] - * 5.times {|i| a.push(i) } # => 5 - * a # => [0, 1, 2, 3, 4] - * - * With no block given, returns an Enumerator. - * - */ - -static VALUE -int_dotimes(VALUE num) -{ - RETURN_SIZED_ENUMERATOR(num, 0, 0, int_dotimes_size); - - if (FIXNUM_P(num)) { - long i, end; - - end = FIX2LONG(num); - for (i=0; i<end; i++) { - rb_yield_1(LONG2FIX(i)); - } - } - else { - VALUE i = INT2FIX(0); - - for (;;) { - if (!RTEST(int_le(i, num))) break; - rb_yield(i); - i = rb_int_plus(i, INT2FIX(1)); - } - } - return num; -} - /* * call-seq: * round(ndigits= 0, half: :up) -> integer @@ -6243,7 +6191,6 @@ Init_Numeric(void) rb_define_method(rb_cInteger, "nobits?", int_nobits_p, 1); rb_define_method(rb_cInteger, "upto", int_upto, 1); rb_define_method(rb_cInteger, "downto", int_downto, 1); - rb_define_method(rb_cInteger, "times", int_dotimes, 0); rb_define_method(rb_cInteger, "succ", int_succ, 0); rb_define_method(rb_cInteger, "next", int_succ, 0); rb_define_method(rb_cInteger, "pred", int_pred, 0); |