diff options
author | tyltr <tylitianrui@126.com> | 2022-04-24 10:35:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-24 17:35:14 +0200 |
commit | 9a0b4d088c35f5200f9f4694be339a28f7a9c6f6 (patch) | |
tree | 9431392f80c8857aa761d344a0b39916f6d147bc /args.go | |
parent | optimize (#1272) (diff) | |
download | fasthttp-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.go | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -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) { |