diff options
author | Ken Thompson <ken@golang.org> | 2009-03-17 13:58:38 -0700 |
---|---|---|
committer | Ken Thompson <ken@golang.org> | 2009-03-17 13:58:38 -0700 |
commit | 4bc43599610ffd9db95ef17ef29f7ae5d12776df (patch) | |
tree | 402ffcd1157623f1f77d69a32b6aecdb5cf3267e /src/cmd/gc/subr.c | |
parent | fff0c79311dfed21fed1f0445beaa628e4a4cb19 (diff) | |
download | golang-4bc43599610ffd9db95ef17ef29f7ae5d12776df.tar.gz |
binary search on type switches.
new feature 'case nil:' in type switch
will match iff the interface is nil.
R=r
OCL=26404
CL=26404
Diffstat (limited to 'src/cmd/gc/subr.c')
-rw-r--r-- | src/cmd/gc/subr.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index a112849a8..eda84820a 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -1919,7 +1919,7 @@ eqargs(Type *t1, Type *t2) } uint32 -typehash(Type *at, int d) +typehash(Type *at, int addsym, int d) { uint32 h; Type *t; @@ -1931,20 +1931,23 @@ typehash(Type *at, int d) h = at->etype*PRIME4; + if(addsym && at->sym != S) + h += stringhash(at->sym->name); + switch(at->etype) { default: - h += PRIME5 * typehash(at->type, d+1); + h += PRIME5 * typehash(at->type, addsym, d+1); break; case TINTER: // botch -- should be sorted? for(t=at->type; t!=T; t=t->down) - h += PRIME6 * typehash(t, d+1); + h += PRIME6 * typehash(t, addsym, d+1); break; case TSTRUCT: for(t=at->type; t!=T; t=t->down) - h += PRIME7 * typehash(t, d+1); + h += PRIME7 * typehash(t, addsym, d+1); break; case TFUNC: @@ -1953,7 +1956,7 @@ typehash(Type *at, int d) if(t != T) t = t->down; for(; t!=T; t=t->down) - h += PRIME7 * typehash(t, d+1); + h += PRIME7 * typehash(t, addsym, d+1); break; } @@ -2756,9 +2759,9 @@ ifaceokT2I(Type *t0, Type *iface, Type **m) // so we can both be wrong together. for(im=iface->type; im; im=im->down) { - imhash = typehash(im, 0); + imhash = typehash(im, 0, 0); tm = ifacelookdot(im->sym, t); - if(tm == T || typehash(tm, 0) != imhash) { + if(tm == T || typehash(tm, 0, 0) != imhash) { *m = im; return 0; } @@ -2778,7 +2781,7 @@ ifaceokI2I(Type *i1, Type *i2, Type **m) for(m2=i2->type; m2; m2=m2->down) { for(m1=i1->type; m1; m1=m1->down) - if(m1->sym == m2->sym && typehash(m1, 0) == typehash(m2, 0)) + if(m1->sym == m2->sym && typehash(m1, 0, 0) == typehash(m2, 0, 0)) goto found; *m = m2; return 0; |