Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
bytes, strings: speed up TrimSpace 4-5x for common ASCII cases #29122
Per thread on golang-dev, I recently found that strings.TrimSpace is quite slow on a lot of common inputs, because it doesn't have a fast path for ASCII strings.
Adding a fast path for ASCII speeds it up 4-5x for ASCII cases, speeds it up somewhat for partially-ASCII cases, and doesn't (noticeably) slow it down for all-non-ASCII cases. So a pretty nice win for heavy users of TrimSpace like GoAWK. :-)
This is similar to #17856, where a similar ASCII fast path was introduced for strings.Fields and bytes.Fields.
For the record, I'm using go version