aboutsummaryrefslogtreecommitdiff
path: root/cookie.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-05 12:47:30 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-05 12:47:30 +0200
commit6fb8b96152377bc55f56a70720c78b430ae78099 (patch)
tree1e08c45fe3c8f36c67f9ae9956f420dd5313ab15 /cookie.go
parentEliminated redundant memory allocation during cookie expiration time parsing (diff)
downloadfasthttp-6fb8b96152377bc55f56a70720c78b430ae78099.tar.gz
fasthttp-6fb8b96152377bc55f56a70720c78b430ae78099.tar.bz2
fasthttp-6fb8b96152377bc55f56a70720c78b430ae78099.zip
Increased cookies' parsing performance
Diffstat (limited to 'cookie.go')
-rw-r--r--cookie.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/cookie.go b/cookie.go
index 116f6a5..e202628 100644
--- a/cookie.go
+++ b/cookie.go
@@ -162,25 +162,31 @@ func (s *cookieScanner) next(kv *argsKV, decode bool) bool {
return false
}
- var b []byte
- n := bytes.IndexByte(s.b, ';')
- if n < 0 {
- b = s.b
- s.b = s.b[len(s.b):]
- } else {
- b = s.b[:n]
- s.b = s.b[n+1:]
+ isKey := true
+ k := 0
+ for i, c := range s.b {
+ switch c {
+ case '=':
+ if isKey {
+ isKey = false
+ kv.key = decodeCookieArg(kv.key[:0], s.b[:i], decode)
+ k = i + 1
+ }
+ case ';':
+ if isKey {
+ kv.key = kv.key[:0]
+ }
+ kv.value = decodeCookieArg(kv.value[:0], s.b[k:i], decode)
+ s.b = s.b[i+1:]
+ return true
+ }
}
- n = bytes.IndexByte(b, '=')
- if n < 0 {
+ if isKey {
kv.key = kv.key[:0]
- kv.value = decodeCookieArg(kv.value[:0], b, decode)
- return true
}
-
- kv.key = decodeCookieArg(kv.key[:0], b[:n], decode)
- kv.value = decodeCookieArg(kv.value[:0], b[n+1:], decode)
+ kv.value = decodeCookieArg(kv.value[:0], s.b[k:], decode)
+ s.b = s.b[len(s.b):]
return true
}