1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:14:43 -07:00

runtime: get rid of goalg, no longer needed

The goalg function was a holdover from when we had algorithm
tables in both C and Go.  It is no longer needed.

Change-Id: Ia0c1af35bef3497a899f22084a1a7b42daae72a0
Reviewed-on: https://go-review.googlesource.com/2099
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Keith Randall 2014-12-27 20:32:11 -08:00
parent 2c987e1693
commit b1f29b2d44
5 changed files with 21 additions and 25 deletions

View File

@ -251,7 +251,7 @@ type rtype struct {
align uint8 // alignment of variable with this type align uint8 // alignment of variable with this type
fieldAlign uint8 // alignment of struct field with this type fieldAlign uint8 // alignment of struct field with this type
kind uint8 // enumeration for C kind uint8 // enumeration for C
alg *typeAlg // algorithm table (../runtime/runtime.h:/Alg) alg *typeAlg // algorithm table
gc [2]unsafe.Pointer // garbage collection data gc [2]unsafe.Pointer // garbage collection data
string *string // string form; unnecessary but undeniably useful string *string // string form; unnecessary but undeniably useful
*uncommonType // (relatively) uncommon fields *uncommonType // (relatively) uncommon fields
@ -259,6 +259,7 @@ type rtype struct {
zero unsafe.Pointer // pointer to zero value zero unsafe.Pointer // pointer to zero value
} }
// a copy of runtime.typeAlg
type typeAlg struct { type typeAlg struct {
// function for hashing objects of this type // function for hashing objects of this type
// (ptr to object, size, seed) -> hash // (ptr to object, size, seed) -> hash

View File

@ -131,7 +131,7 @@ func interhash(p unsafe.Pointer, s, h uintptr) uintptr {
return h return h
} }
t := tab._type t := tab._type
fn := goalg(t.alg).hash fn := t.alg.hash
if fn == nil { if fn == nil {
panic(errorString("hash of unhashable type " + *t._string)) panic(errorString("hash of unhashable type " + *t._string))
} }
@ -148,7 +148,7 @@ func nilinterhash(p unsafe.Pointer, s, h uintptr) uintptr {
if t == nil { if t == nil {
return h return h
} }
fn := goalg(t.alg).hash fn := t.alg.hash
if fn == nil { if fn == nil {
panic(errorString("hash of unhashable type " + *t._string)) panic(errorString("hash of unhashable type " + *t._string))
} }
@ -219,7 +219,7 @@ func efaceeq(p, q interface{}) bool {
if t == nil { if t == nil {
return true return true
} }
eq := goalg(t.alg).equal eq := t.alg.equal
if eq == nil { if eq == nil {
panic(errorString("comparing uncomparable type " + *t._string)) panic(errorString("comparing uncomparable type " + *t._string))
} }
@ -241,7 +241,7 @@ func ifaceeq(p, q interface {
return true return true
} }
t := xtab._type t := xtab._type
eq := goalg(t.alg).equal eq := t.alg.equal
if eq == nil { if eq == nil {
panic(errorString("comparing uncomparable type " + *t._string)) panic(errorString("comparing uncomparable type " + *t._string))
} }
@ -285,11 +285,6 @@ func memclrBytes(b []byte) {
memclr(s.array, uintptr(s.len)) memclr(s.array, uintptr(s.len))
} }
// TODO(dvyukov): remove when Type is converted to Go and contains *typeAlg.
func goalg(a unsafe.Pointer) *typeAlg {
return (*typeAlg)(a)
}
// used in asm_{386,amd64}.s // used in asm_{386,amd64}.s
const hashRandomBytes = ptrSize / 4 * 64 const hashRandomBytes = ptrSize / 4 * 64

View File

@ -251,7 +251,7 @@ func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {
if h == nil || h.count == 0 { if h == nil || h.count == 0 {
return unsafe.Pointer(t.elem.zero) return unsafe.Pointer(t.elem.zero)
} }
alg := goalg(t.key.alg) alg := t.key.alg
hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0)) hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
@ -299,7 +299,7 @@ func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool)
if h == nil || h.count == 0 { if h == nil || h.count == 0 {
return unsafe.Pointer(t.elem.zero), false return unsafe.Pointer(t.elem.zero), false
} }
alg := goalg(t.key.alg) alg := t.key.alg
hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0)) hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + (hash&m)*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + (hash&m)*uintptr(t.bucketsize)))
@ -342,7 +342,7 @@ func mapaccessK(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, unsafe
if h == nil || h.count == 0 { if h == nil || h.count == 0 {
return nil, nil return nil, nil
} }
alg := goalg(t.key.alg) alg := t.key.alg
hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0)) hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + (hash&m)*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + (hash&m)*uintptr(t.bucketsize)))
@ -392,7 +392,7 @@ func mapassign1(t *maptype, h *hmap, key unsafe.Pointer, val unsafe.Pointer) {
raceReadObjectPC(t.elem, val, callerpc, pc) raceReadObjectPC(t.elem, val, callerpc, pc)
} }
alg := goalg(t.key.alg) alg := t.key.alg
hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0)) hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0))
if h.buckets == nil { if h.buckets == nil {
@ -502,7 +502,7 @@ func mapdelete(t *maptype, h *hmap, key unsafe.Pointer) {
if h == nil || h.count == 0 { if h == nil || h.count == 0 {
return return
} }
alg := goalg(t.key.alg) alg := t.key.alg
hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0)) hash := alg.hash(key, uintptr(t.key.size), uintptr(h.hash0))
bucket := hash & (uintptr(1)<<h.B - 1) bucket := hash & (uintptr(1)<<h.B - 1)
if h.oldbuckets != nil { if h.oldbuckets != nil {
@ -609,7 +609,7 @@ func mapiternext(it *hiter) {
b := it.bptr b := it.bptr
i := it.i i := it.i
checkBucket := it.checkBucket checkBucket := it.checkBucket
alg := goalg(t.key.alg) alg := t.key.alg
next: next:
if b == nil { if b == nil {
@ -773,7 +773,7 @@ func growWork(t *maptype, h *hmap, bucket uintptr) {
func evacuate(t *maptype, h *hmap, oldbucket uintptr) { func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
b := (*bmap)(add(h.oldbuckets, oldbucket*uintptr(t.bucketsize))) b := (*bmap)(add(h.oldbuckets, oldbucket*uintptr(t.bucketsize)))
newbit := uintptr(1) << (h.B - 1) newbit := uintptr(1) << (h.B - 1)
alg := goalg(t.key.alg) alg := t.key.alg
if !evacuated(b) { if !evacuated(b) {
// TODO: reuse overflow buckets instead of using new ones, if there // TODO: reuse overflow buckets instead of using new ones, if there
// is no iterator using the old buckets. (If !oldIterator.) // is no iterator using the old buckets. (If !oldIterator.)
@ -904,7 +904,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
} }
func ismapkey(t *_type) bool { func ismapkey(t *_type) bool {
return goalg(t.alg).hash != nil return t.alg.hash != nil
} }
// Reflect stubs. Called from ../reflect/asm_*.s // Reflect stubs. Called from ../reflect/asm_*.s

View File

@ -21,7 +21,7 @@ func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
// One-bucket table. No need to hash. // One-bucket table. No need to hash.
b = (*bmap)(h.buckets) b = (*bmap)(h.buckets)
} else { } else {
hash := goalg(t.key.alg).hash(noescape(unsafe.Pointer(&key)), 4, uintptr(h.hash0)) hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), 4, uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b = (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) b = (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
if c := h.oldbuckets; c != nil { if c := h.oldbuckets; c != nil {
@ -63,7 +63,7 @@ func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) {
// One-bucket table. No need to hash. // One-bucket table. No need to hash.
b = (*bmap)(h.buckets) b = (*bmap)(h.buckets)
} else { } else {
hash := goalg(t.key.alg).hash(noescape(unsafe.Pointer(&key)), 4, uintptr(h.hash0)) hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), 4, uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b = (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) b = (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
if c := h.oldbuckets; c != nil { if c := h.oldbuckets; c != nil {
@ -105,7 +105,7 @@ func mapaccess1_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer {
// One-bucket table. No need to hash. // One-bucket table. No need to hash.
b = (*bmap)(h.buckets) b = (*bmap)(h.buckets)
} else { } else {
hash := goalg(t.key.alg).hash(noescape(unsafe.Pointer(&key)), 8, uintptr(h.hash0)) hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), 8, uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b = (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) b = (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
if c := h.oldbuckets; c != nil { if c := h.oldbuckets; c != nil {
@ -147,7 +147,7 @@ func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) {
// One-bucket table. No need to hash. // One-bucket table. No need to hash.
b = (*bmap)(h.buckets) b = (*bmap)(h.buckets)
} else { } else {
hash := goalg(t.key.alg).hash(noescape(unsafe.Pointer(&key)), 8, uintptr(h.hash0)) hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), 8, uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b = (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) b = (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
if c := h.oldbuckets; c != nil { if c := h.oldbuckets; c != nil {
@ -244,7 +244,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
return unsafe.Pointer(t.elem.zero) return unsafe.Pointer(t.elem.zero)
} }
dohash: dohash:
hash := goalg(t.key.alg).hash(noescape(unsafe.Pointer(&ky)), 2*ptrSize, uintptr(h.hash0)) hash := t.key.alg.hash(noescape(unsafe.Pointer(&ky)), 2*ptrSize, uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
if c := h.oldbuckets; c != nil { if c := h.oldbuckets; c != nil {
@ -344,7 +344,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
return unsafe.Pointer(t.elem.zero), false return unsafe.Pointer(t.elem.zero), false
} }
dohash: dohash:
hash := goalg(t.key.alg).hash(noescape(unsafe.Pointer(&ky)), 2*ptrSize, uintptr(h.hash0)) hash := t.key.alg.hash(noescape(unsafe.Pointer(&ky)), 2*ptrSize, uintptr(h.hash0))
m := uintptr(1)<<h.B - 1 m := uintptr(1)<<h.B - 1
b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
if c := h.oldbuckets; c != nil { if c := h.oldbuckets; c != nil {

View File

@ -16,7 +16,7 @@ type _type struct {
align uint8 align uint8
fieldalign uint8 fieldalign uint8
kind uint8 kind uint8
alg unsafe.Pointer alg *typeAlg
// gc stores _type info required for garbage collector. // gc stores _type info required for garbage collector.
// If (kind&KindGCProg)==0, then gc[0] points at sparse GC bitmap // If (kind&KindGCProg)==0, then gc[0] points at sparse GC bitmap
// (no indirection), 4 bits per word. // (no indirection), 4 bits per word.