Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize #1275

Merged
merged 4 commits into from Apr 24, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions args.go
Expand Up @@ -544,13 +544,22 @@ 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 < 0 && idxPlus < 0 {
// fast path: src doesn't contain encoded chars
return append(dst, src...)
}

idx := min(idxPercent, idxPlus)
if idx > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one of them is -1 you can still start at the other. So I would change this block to be smarter without the min func.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, it would be better

dst = append(dst, src[:idx]...)
} else {
idx = 0
}

// 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 All @@ -573,6 +582,13 @@ func decodeArgAppend(dst, src []byte) []byte {
return dst
}

func min(a, b int) int {
if a <= b {
return a
}
return b
}

// decodeArgAppendNoPlus is almost identical to decodeArgAppend, but it doesn't
// substitute '+' with ' '.
//
Expand Down