1
0
mirror of https://github.com/golang/go synced 2024-11-24 23:27:57 -07:00

strings.TrimSpace micro-optimization

strings.TrimSpace string's end final trimming should use more specific TrimRightFunc instead of common TrimFunc (because start has already trimmed before)
This commit is contained in:
Illirgway 2021-06-21 23:04:01 +03:00 committed by GitHub
parent 3f9ec83b10
commit 040607a831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -884,7 +884,8 @@ func TrimSpace(s string) string {
for ; stop > start; stop-- {
c := s[stop-1]
if c >= utf8.RuneSelf {
return TrimFunc(s[start:stop], unicode.IsSpace)
// start has been already trimmed above, should trim end only
return TrimRightFunc(s[start:stop], unicode.IsSpace)
}
if asciiSpace[c] == 0 {
break