Skip to content

Commit

Permalink
optimize (#1275)
Browse files Browse the repository at this point in the history
* opotimize

* lint

* without min

* less comparisons
  • Loading branch information
tylitianrui committed Apr 24, 2022
1 parent e3d2512 commit 9a0b4d0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions args.go
Expand Up @@ -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) {
Expand Down

0 comments on commit 9a0b4d0

Please sign in to comment.