From 8f5cefb1164d92096a85799ac0f002e7e8b4cb87 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 27 Aug 2020 14:21:57 +0300 Subject: [PATCH] strconv: fix f64_to_str_lnd and f64_to_str_l after 6921d46 --- vlib/strconv/format.v | 6 +++--- vlib/strconv/utilities.v | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vlib/strconv/format.v b/vlib/strconv/format.v index 910c7ac435..57f43e547a 100644 --- a/vlib/strconv/format.v +++ b/vlib/strconv/format.v @@ -128,7 +128,7 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string { // allocate exp+32 chars for the return string //mut res := []byte{len:exp+32,init:`0`} - mut res := [`0`].repeat(exp+32) // TODO: Slow!! is there other possibilities to allocate this? + mut res := []byte{len: exp+32, init: 0} mut r_i := 0 // result string buffer index //println("s:${sgn} b:${b[0]} es:${exp_sgn} exp:${exp}") @@ -182,7 +182,7 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string { } res[r_i] = 0 //println("result: [${tos(&res[0],r_i)}]") - return tos(&res[0],r_i) + return tos(res.data, r_i) } else { if dec_digit > 0 { mut c := 0 @@ -193,7 +193,7 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string { } res[r_i] = 0 } - return tos(&res[0],r_i) + return tos(res.data, r_i) } } diff --git a/vlib/strconv/utilities.v b/vlib/strconv/utilities.v index e9406103b6..e3305a986e 100644 --- a/vlib/strconv/utilities.v +++ b/vlib/strconv/utilities.v @@ -290,7 +290,7 @@ pub fn f64_to_str_l(f f64) string { } // allocate exp+32 chars for the return string - mut res := [`0`].repeat(exp+32) // TODO: Slow!! is there other possibilities to allocate this? + mut res := []byte{len: exp+32, init: 0} mut r_i := 0 // result string buffer index //println("s:${sgn} b:${b[0]} es:${exp_sgn} exp:${exp}") @@ -335,5 +335,5 @@ pub fn f64_to_str_l(f f64) string { } } res[r_i] = 0 - return tos(&res[0],r_i) + return tos(res.data,r_i) }