diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 3c83cb6083713c..ff187b7307bdc0 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -355,14 +355,12 @@ pub fn (s string) replace(rep string, with string) string { if !s.contains(rep) { return s.clone() } - // TODO: PERF Allocating ints is expensive. Should be a stack array - // Get locations of all reps within this string mut pidxs_len := 0 pidxs_cap := s.len / rep.len mut stack_idxs := [replace_stack_buffer_size]int{} mut pidxs := unsafe { &stack_idxs[0] } if pidxs_cap > replace_stack_buffer_size { - pidxs = unsafe { malloc(sizeof(int) * pidxs_cap) } + pidxs = unsafe { &int(malloc(sizeof(int) * pidxs_cap)) } } defer { if pidxs_cap > replace_stack_buffer_size { @@ -1262,7 +1260,7 @@ fn (s string) index_kmp(p string) int { mut stack_prefixes := [kmp_stack_buffer_size]int{} mut p_prefixes := unsafe { &stack_prefixes[0] } if p.len > kmp_stack_buffer_size { - p_prefixes = unsafe { vcalloc(p.len * sizeof(int)) } + p_prefixes = unsafe { &int(vcalloc(p.len * sizeof(int))) } } defer { if p.len > kmp_stack_buffer_size {