aboutsummaryrefslogtreecommitdiff
path: root/args.go
diff options
context:
space:
mode:
authorGravatar tyltr <tylitianrui@126.com> 2022-04-24 10:35:14 -0500
committerGravatar GitHub <noreply@github.com> 2022-04-24 17:35:14 +0200
commit9a0b4d088c35f5200f9f4694be339a28f7a9c6f6 (patch)
tree9431392f80c8857aa761d344a0b39916f6d147bc /args.go
parentoptimize (#1272) (diff)
downloadfasthttp-9a0b4d088c35f5200f9f4694be339a28f7a9c6f6.tar.gz
fasthttp-9a0b4d088c35f5200f9f4694be339a28f7a9c6f6.tar.bz2
fasthttp-9a0b4d088c35f5200f9f4694be339a28f7a9c6f6.zip
optimize (#1275)
* opotimize * lint * without min * less comparisons
Diffstat (limited to 'args.go')
-rw-r--r--args.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/args.go b/args.go
index 844d931..dc10ea1 100644
--- a/args.go
+++ b/args.go
@@ -544,13 +544,28 @@ func (s *argsScanner) next(kv *argsKV) bool {
}
func decodeArgAppend(dst, src []byte) []byte {
- if bytes.IndexByte(src, '%') < 0 && bytes.IndexByte(src, '+') < 0 {
+ idxPercent := bytes.IndexByte(src, '%')
+ idxPlus := bytes.IndexByte(src, '+')
+ if idxPercent == -1 && idxPlus == -1 {
// fast path: src doesn't contain encoded chars
return append(dst, src...)
}
+ idx := 0
+ if idxPercent == -1 {
+ idx = idxPlus
+ } else if idxPlus == -1 {
+ idx = idxPercent
+ } else if idxPercent > idxPlus {
+ idx = idxPlus
+ } else {
+ idx = idxPercent
+ }
+
+ dst = append(dst, src[:idx]...)
+
// slow path
- for i := 0; i < len(src); i++ {
+ for i := idx; i < len(src); i++ {
c := src[i]
if c == '%' {
if i+2 >= len(src) {