diff options
author | Mau Magnaguagno <maumagnaguagno@gmail.com> | 2023-11-08 12:37:19 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-08 10:37:19 -0500 |
commit | eb2abc3f16685979ea87861900fb33b3a975589e (patch) | |
tree | d899ef17d2dcabc10ef9a1bb260d6ff429b1f810 /yjit.rb | |
parent | 50402db5a7d3bb2a9a93d63a63295b4d85a68088 (diff) |
YJIT: refactor format_number (#8869)
Replace enumerators with simpler and faster version that only inserts commas before '.' or end of integer string.
Diffstat (limited to 'yjit.rb')
-rw-r--r-- | yjit.rb | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -437,11 +437,10 @@ module RubyVM::YJIT # Format large numbers with comma separators for readability def format_number(pad, number) - integer, decimal = number.to_s.split(".") - d_groups = integer.chars.reverse.each_slice(3) - with_commas = d_groups.map(&:join).join(',').reverse - formatted = [with_commas, decimal].compact.join(".") - formatted.rjust(pad, ' ') + s = number.to_s + i = s.index('.') || s.size + s.insert(i -= 3, ',') while i > 3 + s.rjust(pad, ' ') end # Format a number along with a percentage over a total value |