From 0b739f6f267faafd4e9c96f4efc8467a3be713c8 Mon Sep 17 00:00:00 2001 From: malc Date: Sat, 29 Jun 2019 01:18:15 +0300 Subject: [PATCH] Use 4.08s %#d format specifier --- utils.ml | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/utils.ml b/utils.ml index ecb48e8..8f6c055 100644 --- a/utils.ml +++ b/utils.ml @@ -81,28 +81,14 @@ let int_of_string_with_suffix s = ;; let string_with_suffix_of_int n = - if n = 0 - then "0" - else - let units = [(30, "G"); (20, "M"); (10, "K")] in - let prettyint n = - let rec loop s n = - let h = n mod 1000 in - let n = n / 1000 in - if n = 0 - then string_of_int h ^ s - else loop (Printf.sprintf "_%03d%s" h s) n - in - loop E.s n - in - let rec find = function - | [] -> prettyint n - | (shift, suffix) :: rest -> - if (n land ((1 lsl shift) - 1)) = 0 - then prettyint (n lsr shift) ^ suffix - else find rest - in - find units + let rec find = function + | [] -> Printf.sprintf "%#d" n + | (shift, suffix) :: rest -> + if (n land ((1 lsl shift) - 1)) = 0 + then Printf.sprintf "%#d%c" (n lsr shift) suffix + else find rest + in + if n = 0 then "0" else find [(30, 'G'); (20, 'M'); (10, 'K')] ;; let color_of_string s = -- 2.11.4.GIT