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

string: make replace() clone for now; parser: comptime method

This commit is contained in:
Alexander Medvednikov
2020-05-25 08:17:36 +02:00
parent 1b36d7a037
commit f41e2c0a4b
3 changed files with 51 additions and 4 deletions

View File

@ -156,7 +156,7 @@ pub fn (s string) replace_once(rep, with string) string {
pub fn (s string) replace(rep, with string) string {
if s.len == 0 || rep.len == 0 {
return s
return s.clone()
}
// TODO PERF Allocating ints is expensive. Should be a stack array
// Get locations of all reps within this string
@ -172,7 +172,7 @@ pub fn (s string) replace(rep, with string) string {
}
// Dont change the string if there's nothing to replace
if idxs.len == 0 {
return s
return s.clone()
}
// Now we know the number of replacements we need to do and we can calc the len of the new string
new_len := s.len + idxs.len * (with.len - rep.len)
@ -1229,7 +1229,7 @@ pub fn (s string) all_after_last(dot string) string {
return s.right(pos + dot.len)
}
pub fn (s string) after(dot string) string {
pub fn (s string) after(dot string) string {
return s.all_after_last(dot)
}