Skip to content

Commit e7c56fe

Browse files
Illirgwaygopherbot
authored andcommitted
strings: adding micro-optimization for TrimSpace
replace for string's end trimming TrimFunc -> TrimRightFunc strings.TrimSpace string's end trimming should use more specific TrimRightFunc instead of common TrimFunc (because start has already trimmed before) Change-Id: I827f1a25c141e61edfe1f8b11f6e8cd685f8b384 GitHub-Last-Rev: 040607a GitHub-Pull-Request: #46862 Reviewed-on: https://go-review.googlesource.com/c/go/+/329731 Auto-Submit: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Russ Cox <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent a5dd684 commit e7c56fe

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/strings/strings.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,8 @@ func TrimSpace(s string) string {
962962
for ; stop > start; stop-- {
963963
c := s[stop-1]
964964
if c >= utf8.RuneSelf {
965-
return TrimFunc(s[start:stop], unicode.IsSpace)
965+
// start has been already trimmed above, should trim end only
966+
return TrimRightFunc(s[start:stop], unicode.IsSpace)
966967
}
967968
if asciiSpace[c] == 0 {
968969
break

0 commit comments

Comments
 (0)