]> Cypherpunks repositories - gostls13.git/commit
strings: implement a faster byte->byte Replacer
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 3 Oct 2011 20:12:01 +0000 (13:12 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 3 Oct 2011 20:12:01 +0000 (13:12 -0700)
commitf75ff01f44f0fa90080bbd9aa3656f0a6fa49042
treecb3224555b98f173dc3bc21ececaeef3d6d1b6d2
parent85916146ea0f63fd9a1b8e1c224eae261ff337ba
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
src/pkg/http/cookie.go
src/pkg/strings/export_test.go [new file with mode: 0644]
src/pkg/strings/replace.go
src/pkg/strings/replace_test.go