perf: avoid unnecessary byte/string conversion (#10012)

We can use alternative functions to avoid unnecessary byte/string
conversion calls and reduce allocations.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun 2023-06-01 22:29:47 +08:00 committed by GitHub
parent 19de8af350
commit d02ba28b96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View file

@ -143,7 +143,7 @@ func ValidMethod(method string) bool {
// ValidHeader checks is the provided string satisfies the header's name regex
func ValidHeader(header string) bool {
return headerRegexp.Match([]byte(header))
return headerRegexp.MatchString(header)
}
// ValidCacheDuration checks if the provided string is a valid cache duration
@ -159,13 +159,13 @@ func ValidCacheDuration(duration string) bool {
if len(element) == 0 {
continue
}
if statusCodeRegex.Match([]byte(element)) {
if statusCodeRegex.MatchString(element) {
if seenDuration {
return false // code after duration
}
continue
}
if durationRegex.Match([]byte(element)) {
if durationRegex.MatchString(element) {
seenDuration = true
}
}