From ea3ac6ba75c5b7496b29117687b0859ad40f3f39 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Wed, 6 Aug 2014 13:42:00 -0700 Subject: [PATCH] runtime: shorten hash declarations LGTM=iant R=dvyukov, iant CC=golang-codereviews https://golang.org/cl/117680044 --- src/cmd/api/goapi.go | 2 +- src/pkg/runtime/alg.go | 34 ++++++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index 932b5520f4..fe3c257a55 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -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) { // 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) if err != nil { log.Fatalf("incorrect generated file: %s", err) diff --git a/src/pkg/runtime/alg.go b/src/pkg/runtime/alg.go index e2917dabb6..251374a946 100644 --- a/src/pkg/runtime/alg.go +++ b/src/pkg/runtime/alg.go @@ -42,9 +42,9 @@ const nacl = GOOS == "nacl" var use_aeshash bool // 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 { return aeshash(p, s, h) } @@ -58,7 +58,7 @@ func memhash(p unsafe.Pointer, s uintptr, h uintptr) uintptr { 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) } @@ -67,7 +67,7 @@ func strhash(a *string, s uintptr, h uintptr) uintptr { // To avoid long hash chains, we assign a random number // 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 switch { 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 switch { 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)) 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)) 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")) } -func interhash(a *interface { - f() -}, s uintptr, h uintptr) uintptr { - tab := (*iface)(unsafe.Pointer(a)).tab +func interhash(a *iface, s, h uintptr) uintptr { + tab := a.tab if tab == nil { return h } @@ -123,14 +121,14 @@ func interhash(a *interface { panic(errorString("hash of unhashable type " + *t._string)) } 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 { - 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 { - t := (*eface)(unsafe.Pointer(a))._type +func nilinterhash(a *eface, s, h uintptr) uintptr { + t := a._type if t == nil { return h } @@ -141,9 +139,9 @@ func nilinterhash(a *interface{}, s uintptr, h uintptr) uintptr { panic(errorString("hash of unhashable type " + *t._string)) } 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 { - return c1 * fn((*eface)(unsafe.Pointer(a)).data, uintptr(t.size), h^c0) + return c1 * fn(a.data, uintptr(t.size), h^c0) } } -- 2.48.1