From 19f4b06b9d9698c97bad5f342324517455be6843 Mon Sep 17 00:00:00 2001 From: Reznov <78517110+alantudyk@users.noreply.github.com> Date: Mon, 8 Apr 2024 06:51:32 +0300 Subject: [PATCH] Reducing the number of divisions in `rb_fix_digits` --- numeric.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numeric.c b/numeric.c index f0a0e3c279..f613d4120d 100644 --- a/numeric.c +++ b/numeric.c @@ -5453,11 +5453,12 @@ rb_fix_digits(VALUE fix, long base) return rb_ary_new_from_args(1, INT2FIX(0)); digits = rb_ary_new(); - while (x > 0) { + while (x >= base) { long q = x % base; rb_ary_push(digits, LONG2NUM(q)); x /= base; } + rb_ary_push(digits, LONG2NUM(x)); return digits; }