Skip to content

Commit

Permalink
strings.TrimSpace micro-optimization
Browse files Browse the repository at this point in the history
strings.TrimSpace string's end final trimming should use more specific TrimRightFunc instead of common TrimFunc (because start has already trimmed before)
  • Loading branch information
Illirgway committed Jun 21, 2021
1 parent 3f9ec83 commit 040607a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/strings/strings.go
Expand Up @@ -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
Expand Down

0 comments on commit 040607a

Please sign in to comment.