From 77f3e189d2bd4eb015235d200ca75803e45c87ef Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Sun, 5 Aug 2012 21:35:41 +0200 Subject: runtime: faster string equality. benchmark old ns/op new ns/op delta BenchmarkCompareStringEqual 51 35 -30.20% BenchmarkCompareStringIdentical 51 7 -85.71% BenchmarkCompareStringSameLength 25 18 -28.29% BenchmarkCompareStringDifferentLength 2 2 +1.46% R=golang-dev, rsc CC=golang-dev, remy https://golang.org/cl/6450092 --- src/pkg/runtime/string.goc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/pkg/runtime/string.goc') diff --git a/src/pkg/runtime/string.goc b/src/pkg/runtime/string.goc index 7cab6d2417..b72a1aa5e7 100644 --- a/src/pkg/runtime/string.goc +++ b/src/pkg/runtime/string.goc @@ -204,6 +204,26 @@ func cmpstring(s1 String, s2 String) (v int32) { v = cmpstring(s1, s2); } +func eqstring(s1 String, s2 String) (v bool) { + uint32 i, l; + + if(s1.len != s2.len) { + v = false; + return; + } + if(s1.str == s2.str) { + v = true; + return; + } + l = s1.len; + for(i=0; i