1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: a small optimization in string.replace()

This commit is contained in:
Alexander Medvednikov 2021-05-22 14:35:33 +03:00
parent 565dbc4051
commit 7c0f8f7644

View File

@ -279,6 +279,9 @@ pub fn (s string) replace(rep string, with string) string {
if s.len == 0 || rep.len == 0 || rep.len > s.len {
return s.clone()
}
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 idxs := []int{cap: s.len / rep.len}