diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2011-10-03 13:12:01 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2011-10-03 13:12:01 -0700 |
| commit | f75ff01f44f0fa90080bbd9aa3656f0a6fa49042 (patch) | |
| tree | cb3224555b98f173dc3bc21ececaeef3d6d1b6d2 /src/pkg/http | |
| parent | 85916146ea0f63fd9a1b8e1c224eae261ff337ba (diff) | |
| download | go-f75ff01f44f0fa90080bbd9aa3656f0a6fa49042.tar.xz | |
strings: implement a faster byte->byte Replacer
When all old & new string values are single bytes,
byteReplacer is now used, instead of the generic
algorithm.
BenchmarkGenericMatch 10000 102519 ns/op
BenchmarkByteByteMatch 1000000 2178 ns/op
fast path, when nothing matches:
BenchmarkByteByteNoMatch 1000000 1109 ns/op
comparisons to multiple Replace calls:
BenchmarkByteByteReplaces 100000 16164 ns/op
comparison to strings.Map:
BenchmarkByteByteMap 500000 5454 ns/op
R=rsc
CC=golang-dev
https://golang.org/cl/5175050
Diffstat (limited to 'src/pkg/http')
| -rw-r--r-- | src/pkg/http/cookie.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/pkg/http/cookie.go b/src/pkg/http/cookie.go index fe70431bbb..6935014324 100644 --- a/src/pkg/http/cookie.go +++ b/src/pkg/http/cookie.go @@ -207,17 +207,16 @@ func readCookies(h Header, filter string) []*Cookie { return cookies } +var cookieNameSanitizer = strings.NewReplacer("\n", "-", "\r", "-") + func sanitizeName(n string) string { - n = strings.Replace(n, "\n", "-", -1) - n = strings.Replace(n, "\r", "-", -1) - return n + return cookieNameSanitizer.Replace(n) } +var cookieValueSanitizer = strings.NewReplacer("\n", " ", "\r", " ", ";", " ") + func sanitizeValue(v string) string { - v = strings.Replace(v, "\n", " ", -1) - v = strings.Replace(v, "\r", " ", -1) - v = strings.Replace(v, ";", " ", -1) - return v + return cookieValueSanitizer.Replace(v) } func unquoteCookieValue(v string) string { |
