From a9894d8a034d4be7cb255d4373f367adc26498c7 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Fri, 11 Oct 2024 23:14:46 +0200 Subject: [PATCH] fix a performance issue --- src/std_fns.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/std_fns.rs b/src/std_fns.rs index 315da3b..b4a8e88 100644 --- a/src/std_fns.rs +++ b/src/std_fns.rs @@ -906,7 +906,8 @@ pub fn str_to_mega_radix(stack: &mut Stack) -> OError { pub fn mega_to_str_radix(stack: &mut Stack) -> OError { require_int_on_stack!(radix, stack, "mega-to-str-radix"); require_on_stack!(mega, Mega, stack, "mega-to-str-radix"); - let mut result = Vec::new(); + // capacity because O(n) + let mut result = Vec::with_capacity((mega as f64).powf(1.0 / radix as f64) as usize + 2); let neg = mega < 0; let mut mega = mega; if neg {