]> Cypherpunks repositories - gostls13.git/commit
runtime: optimize some hash lookups.
authorKeith Randall <khr@golang.org>
Wed, 31 Jul 2013 04:39:57 +0000 (21:39 -0700)
committerKeith Randall <khr@golang.org>
Wed, 31 Jul 2013 04:39:57 +0000 (21:39 -0700)
commita696ae56db451f2f02ffdf63092e0c06dba1d0c5
tree66ff92580fed2aec6082c3c8b2b14dbfbe9124de
parent609d742e791eebceddaeae419b3b909594f4e404
runtime: optimize some hash lookups.

When comparing strings, check these (in order):
- length mismatch => not equal
- string pointer equal => equal
- if length is short:
  - memeq on body
- if length is long:
  - compare first&last few bytes, if different => not equal
  - save entry as a possible match
  - after checking every entry, if there is only one possible
    match, use memeq on that entry.  Otherwise, fallback to hash.

benchmark                 old ns/op    new ns/op    delta
BenchmarkSameLengthMap           43            4  -89.77%

Fixes #5194.
Update #3885.

R=golang-dev, bradfitz, khr, rsc
CC=golang-dev
https://golang.org/cl/12128044
src/pkg/runtime/hashmap.c
src/pkg/runtime/hashmap_fast.c
src/pkg/runtime/mapspeed_test.go