diff options
| author | Russ Cox <rsc@golang.org> | 2011-12-12 22:22:09 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-12-12 22:22:09 -0500 |
| commit | 196b6630759c6f4125c22445dd5b6cfec5faf34b (patch) | |
| tree | 43ae44cf228030c8358410af212994bca7f74e7f /src/pkg/runtime/alg.c | |
| parent | 83f648c9625343045da1e6b4ecc3d207c84403b3 (diff) | |
| download | go-196b6630759c6f4125c22445dd5b6cfec5faf34b.tar.xz | |
gc: implement == on structs and arrays
To allow these types as map keys, we must fill in
equal and hash functions in their algorithm tables.
Structs or arrays that are "just memory", like [2]int,
can and do continue to use the AMEM algorithm.
Structs or arrays that contain special values like
strings or interface values use generated functions
for both equal and hash.
The runtime helper func runtime.equal(t, x, y) bool handles
the general equality case for x == y and calls out to
the equal implementation in the algorithm table.
For short values (<= 4 struct fields or array elements),
the sequence of elementwise comparisons is inlined
instead of calling runtime.equal.
R=ken, mpimenov
CC=golang-dev
https://golang.org/cl/5451105
Diffstat (limited to 'src/pkg/runtime/alg.c')
| -rw-r--r-- | src/pkg/runtime/alg.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/pkg/runtime/alg.c b/src/pkg/runtime/alg.c index e995b0f5a7..8d6fffcfaa 100644 --- a/src/pkg/runtime/alg.c +++ b/src/pkg/runtime/alg.c @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "runtime.h" +#include "type.h" /* * map and chan helpers for @@ -68,7 +69,7 @@ runtime·memprint(uintptr s, void *a) v = *(uint16*)a; break; case 4: - v = *(uintptr*)a; + v = *(uint32*)a; break; case 8: v = *(uint64*)a; @@ -343,3 +344,18 @@ runtime·algarray[] = [ANOEQ128] { runtime·nohash, runtime·noequal, runtime·memprint, runtime·memcopy128 }, }; +// Runtime helpers. + +// func equal(t *Type, x T, y T) (ret bool) +#pragma textflag 7 +void +runtime·equal(Type *t, ...) +{ + byte *x, *y; + bool *ret; + + x = (byte*)(&t+1); + y = x + t->size; + ret = (bool*)(y + t->size); + t->alg->equal(ret, t->size, x, y); +} |
