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

string: avoid double allocation in trim_space()

This commit is contained in:
Rendims 2019-07-22 21:35:01 +02:00 committed by Alexander Medvednikov
parent dd070e616d
commit 5375038d88

View File

@ -545,13 +545,12 @@ pub fn (s string) trim_space() string {
for i < s.len && is_space(s[i]) {
i++
}
mut res := s.right(i)
mut end := res.len - 1
for end >= 0 && is_space(res[end]) {
mut end := s.len - 1
for end >= 0 && is_space(s[end]) {
// C.printf('end=%d c=%d %c\n', end, res.str[end])
end--
}
res = res.left(end + 1)
res := s.substr(i, end + 1)
// println('after SPACE "$res"')
return res
}