Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Delta Between Two Patch Sets: src/pkg/runtime/alg.go

Issue 125720044: code review 125720044: runtime: use better hash for non-empty interface (Closed)
Left Patch Set: Created 10 years, 7 months ago
Right Patch Set: diff -r 37cd24716bed45f655a17ffdc06d769135c77191 https://code.google.com/p/go/ Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/runtime/iface.goc » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2014 The Go Authors. All rights reserved. 1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package runtime 5 package runtime
6 6
7 import "unsafe" 7 import "unsafe"
8 8
9 const ( 9 const (
10 c0 = uintptr((8-uint64(ptrSize))/4*2860486313 + (uint64(ptrSize)-4)/4*33 054211828000289) 10 c0 = uintptr((8-uint64(ptrSize))/4*2860486313 + (uint64(ptrSize)-4)/4*33 054211828000289)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return f64hash(&x[1], 4, f64hash(&x[0], 4, h)) 104 return f64hash(&x[1], 4, f64hash(&x[0], 4, h))
105 } 105 }
106 106
107 func nohash(a unsafe.Pointer, s uintptr, h uintptr) uintptr { 107 func nohash(a unsafe.Pointer, s uintptr, h uintptr) uintptr {
108 panic(errorString("hash of unhashable type")) 108 panic(errorString("hash of unhashable type"))
109 } 109 }
110 110
111 func interhash(a *interface { 111 func interhash(a *interface {
112 f() 112 f()
113 }, s uintptr, h uintptr) uintptr { 113 }, s uintptr, h uintptr) uintptr {
114 » return 0 114 » tab := (*iface)(unsafe.Pointer(a)).tab
115 » if tab == nil {
116 » » return h
117 » }
118 » t := tab._type
119 » fn := goalg(t.alg).hash
120 » if **(**uintptr)(unsafe.Pointer(&fn)) == nohashcode {
121 » » // calling nohash will panic too,
122 » » // but we can print a better error.
123 » » panic(errorString("hash of unhashable type " + *t._string))
124 » }
125 » if uintptr(t.size) <= ptrSize {
126 » » return c1 * fn(unsafe.Pointer(&(*eface)(unsafe.Pointer(a)).data) , uintptr(t.size), h^c0)
127 » } else {
128 » » return c1 * fn((*eface)(unsafe.Pointer(a)).data, uintptr(t.size) , h^c0)
129 » }
115 } 130 }
116 131
117 func nilinterhash(a *interface{}, s uintptr, h uintptr) uintptr { 132 func nilinterhash(a *interface{}, s uintptr, h uintptr) uintptr {
118 t := (*eface)(unsafe.Pointer(a))._type 133 t := (*eface)(unsafe.Pointer(a))._type
119 if t == nil { 134 if t == nil {
120 return h 135 return h
121 } 136 }
122 fn := goalg(t.alg).hash 137 fn := goalg(t.alg).hash
123 if **(**uintptr)(unsafe.Pointer(&fn)) == nohashcode { 138 if **(**uintptr)(unsafe.Pointer(&fn)) == nohashcode {
124 // calling nohash will panic too, 139 // calling nohash will panic too,
(...skipping 21 matching lines...) Expand all
146 return goalg(&algarray[alg_MEM]).hash(*(*unsafe.Pointer)(unsafe.Pointer( &b)), uintptr(len(b)), seed) 161 return goalg(&algarray[alg_MEM]).hash(*(*unsafe.Pointer)(unsafe.Pointer( &b)), uintptr(len(b)), seed)
147 } 162 }
148 163
149 func int32Hash(i uint32, seed uintptr) uintptr { 164 func int32Hash(i uint32, seed uintptr) uintptr {
150 return goalg(&algarray[alg_MEM32]).hash(noescape(unsafe.Pointer(&i)), 4, seed) 165 return goalg(&algarray[alg_MEM32]).hash(noescape(unsafe.Pointer(&i)), 4, seed)
151 } 166 }
152 167
153 func int64Hash(i uint64, seed uintptr) uintptr { 168 func int64Hash(i uint64, seed uintptr) uintptr {
154 return goalg(&algarray[alg_MEM64]).hash(noescape(unsafe.Pointer(&i)), 8, seed) 169 return goalg(&algarray[alg_MEM64]).hash(noescape(unsafe.Pointer(&i)), 8, seed)
155 } 170 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b