♻️ Refactor: replace isInCharset with bytes.IndexByte (#3342)

pull/3343/head
Kashiwa 2025-03-07 22:33:22 +08:00 committed by GitHub
parent 4177ab4086
commit 600ebd95ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 12 deletions

2
ctx.go
View File

@ -1349,7 +1349,7 @@ func (c *DefaultCtx) getLocationFromRoute(route Route, params Map) (string, erro
for key, val := range params {
isSame := key == segment.ParamName || (!c.app.config.CaseSensitive && utils.EqualFold(key, segment.ParamName))
isGreedy := segment.IsGreedy && len(key) == 1 && isInCharset(key[0], greedyParameters)
isGreedy := segment.IsGreedy && len(key) == 1 && bytes.IndexByte(greedyParameters, key[0]) != -1
if isSame || isGreedy {
_, err := buf.WriteString(utils.ToString(val))
if err != nil {

13
path.go
View File

@ -7,6 +7,7 @@
package fiber
import (
"bytes"
"regexp"
"strconv"
"strings"
@ -308,7 +309,7 @@ func (routeParser *routeParser) analyseParameterPart(pattern string, customConst
parameterEndPosition = 0
case parameterEndPosition == -1:
parameterEndPosition = len(pattern) - 1
case !isInCharset(pattern[parameterEndPosition+1], parameterDelimiterChars):
case bytes.IndexByte(parameterDelimiterChars, pattern[parameterEndPosition+1]) == -1:
parameterEndPosition++
}
@ -397,16 +398,6 @@ func (routeParser *routeParser) analyseParameterPart(pattern string, customConst
return n, segment
}
// isInCharset check is the given character in the charset list
func isInCharset(searchChar byte, charset []byte) bool {
for _, char := range charset {
if char == searchChar {
return true
}
}
return false
}
// findNextCharsetPosition search the next char position from the charset
func findNextCharsetPosition(search string, charset []byte) int {
nextPosition := -1