зеркало из https://github.com/github/ruby.git
YJIT: refactor format_number (#8869)
Replace enumerators with simpler and faster version that only inserts commas before '.' or end of integer string.
This commit is contained in:
Родитель
50402db5a7
Коммит
eb2abc3f16
9
yjit.rb
9
yjit.rb
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче