mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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
This commit is contained in:
parent
83f648c962
commit
196b663075
24 changed files with 1174 additions and 163 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue