mirror of
https://github.com/golang/go
synced 2024-11-19 06:04:39 -07:00
runtime: shorten hash declarations
LGTM=iant R=dvyukov, iant CC=golang-codereviews https://golang.org/cl/117680044
This commit is contained in:
parent
f098a29630
commit
ea3ac6ba75
@ -378,7 +378,7 @@ func (w *Walker) parseFile(dir, file string) (*ast.File, error) {
|
|||||||
}
|
}
|
||||||
if w.context != nil && file == fmt.Sprintf("zruntime_defs_%s_%s.go", w.context.GOOS, w.context.GOARCH) {
|
if w.context != nil && file == fmt.Sprintf("zruntime_defs_%s_%s.go", w.context.GOOS, w.context.GOARCH) {
|
||||||
// Just enough to keep the api checker happy.
|
// Just enough to keep the api checker happy.
|
||||||
src := "package runtime; type maptype struct{}; type _type struct{}; type alg struct{}; type mspan struct{}; type m struct{}; type lock struct{}; type slicetype struct{};"
|
src := "package runtime; type maptype struct{}; type _type struct{}; type alg struct{}; type mspan struct{}; type m struct{}; type lock struct{}; type slicetype struct{}; type iface struct{}; type eface struct{}"
|
||||||
f, err = parser.ParseFile(fset, filename, src, 0)
|
f, err = parser.ParseFile(fset, filename, src, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("incorrect generated file: %s", err)
|
log.Fatalf("incorrect generated file: %s", err)
|
||||||
|
@ -42,9 +42,9 @@ const nacl = GOOS == "nacl"
|
|||||||
var use_aeshash bool
|
var use_aeshash bool
|
||||||
|
|
||||||
// in asm_*.s
|
// in asm_*.s
|
||||||
func aeshash(p unsafe.Pointer, s uintptr, h uintptr) uintptr
|
func aeshash(p unsafe.Pointer, s, h uintptr) uintptr
|
||||||
|
|
||||||
func memhash(p unsafe.Pointer, s uintptr, h uintptr) uintptr {
|
func memhash(p unsafe.Pointer, s, h uintptr) uintptr {
|
||||||
if !nacl && use_aeshash {
|
if !nacl && use_aeshash {
|
||||||
return aeshash(p, s, h)
|
return aeshash(p, s, h)
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func memhash(p unsafe.Pointer, s uintptr, h uintptr) uintptr {
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func strhash(a *string, s uintptr, h uintptr) uintptr {
|
func strhash(a *string, s, h uintptr) uintptr {
|
||||||
return memhash((*stringStruct)(unsafe.Pointer(a)).str, uintptr(len(*a)), h)
|
return memhash((*stringStruct)(unsafe.Pointer(a)).str, uintptr(len(*a)), h)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ func strhash(a *string, s uintptr, h uintptr) uintptr {
|
|||||||
// To avoid long hash chains, we assign a random number
|
// To avoid long hash chains, we assign a random number
|
||||||
// as the hash value for a NaN.
|
// as the hash value for a NaN.
|
||||||
|
|
||||||
func f32hash(a *float32, s uintptr, h uintptr) uintptr {
|
func f32hash(a *float32, s, h uintptr) uintptr {
|
||||||
f := *a
|
f := *a
|
||||||
switch {
|
switch {
|
||||||
case f == 0:
|
case f == 0:
|
||||||
@ -79,7 +79,7 @@ func f32hash(a *float32, s uintptr, h uintptr) uintptr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func f64hash(a *float64, s uintptr, h uintptr) uintptr {
|
func f64hash(a *float64, s, h uintptr) uintptr {
|
||||||
f := *a
|
f := *a
|
||||||
switch {
|
switch {
|
||||||
case f == 0:
|
case f == 0:
|
||||||
@ -94,24 +94,22 @@ func f64hash(a *float64, s uintptr, h uintptr) uintptr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func c64hash(a *complex64, s uintptr, h uintptr) uintptr {
|
func c64hash(a *complex64, s, h uintptr) uintptr {
|
||||||
x := (*[2]float32)(unsafe.Pointer(a))
|
x := (*[2]float32)(unsafe.Pointer(a))
|
||||||
return f32hash(&x[1], 4, f32hash(&x[0], 4, h))
|
return f32hash(&x[1], 4, f32hash(&x[0], 4, h))
|
||||||
}
|
}
|
||||||
|
|
||||||
func c128hash(a *complex128, s uintptr, h uintptr) uintptr {
|
func c128hash(a *complex128, s, h uintptr) uintptr {
|
||||||
x := (*[2]float64)(unsafe.Pointer(a))
|
x := (*[2]float64)(unsafe.Pointer(a))
|
||||||
return f64hash(&x[1], 4, f64hash(&x[0], 4, h))
|
return f64hash(&x[1], 4, f64hash(&x[0], 4, h))
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohash(a unsafe.Pointer, s uintptr, h uintptr) uintptr {
|
func nohash(a unsafe.Pointer, s, h uintptr) uintptr {
|
||||||
panic(errorString("hash of unhashable type"))
|
panic(errorString("hash of unhashable type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func interhash(a *interface {
|
func interhash(a *iface, s, h uintptr) uintptr {
|
||||||
f()
|
tab := a.tab
|
||||||
}, s uintptr, h uintptr) uintptr {
|
|
||||||
tab := (*iface)(unsafe.Pointer(a)).tab
|
|
||||||
if tab == nil {
|
if tab == nil {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
@ -123,14 +121,14 @@ func interhash(a *interface {
|
|||||||
panic(errorString("hash of unhashable type " + *t._string))
|
panic(errorString("hash of unhashable type " + *t._string))
|
||||||
}
|
}
|
||||||
if uintptr(t.size) <= ptrSize {
|
if uintptr(t.size) <= ptrSize {
|
||||||
return c1 * fn(unsafe.Pointer(&(*eface)(unsafe.Pointer(a)).data), uintptr(t.size), h^c0)
|
return c1 * fn(unsafe.Pointer(&a.data), uintptr(t.size), h^c0)
|
||||||
} else {
|
} else {
|
||||||
return c1 * fn((*eface)(unsafe.Pointer(a)).data, uintptr(t.size), h^c0)
|
return c1 * fn(a.data, uintptr(t.size), h^c0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func nilinterhash(a *interface{}, s uintptr, h uintptr) uintptr {
|
func nilinterhash(a *eface, s, h uintptr) uintptr {
|
||||||
t := (*eface)(unsafe.Pointer(a))._type
|
t := a._type
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
@ -141,9 +139,9 @@ func nilinterhash(a *interface{}, s uintptr, h uintptr) uintptr {
|
|||||||
panic(errorString("hash of unhashable type " + *t._string))
|
panic(errorString("hash of unhashable type " + *t._string))
|
||||||
}
|
}
|
||||||
if uintptr(t.size) <= ptrSize {
|
if uintptr(t.size) <= ptrSize {
|
||||||
return c1 * fn(unsafe.Pointer(&(*eface)(unsafe.Pointer(a)).data), uintptr(t.size), h^c0)
|
return c1 * fn(unsafe.Pointer(&a.data), uintptr(t.size), h^c0)
|
||||||
} else {
|
} else {
|
||||||
return c1 * fn((*eface)(unsafe.Pointer(a)).data, uintptr(t.size), h^c0)
|
return c1 * fn(a.data, uintptr(t.size), h^c0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user