fix a performance issue

This commit is contained in:
Daniella 2024-10-11 23:14:46 +02:00
parent 1c1f9a4566
commit a9894d8a03

View file

@ -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 {