Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(52)

Delta Between Two Patch Sets: src/pkg/runtime/iface.goc

Issue 125720044: code review 125720044: runtime: use better hash for non-empty interface (Closed)
Left Patch Set: Created 10 years, 7 months ago
Right Patch Set: diff -r 37cd24716bed45f655a17ffdc06d769135c77191 https://code.google.com/p/go/ Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/alg.go ('k') | src/pkg/runtime/runtime.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package runtime 5 package runtime
6 #include "runtime.h" 6 #include "runtime.h"
7 #include "arch_GOARCH.h" 7 #include "arch_GOARCH.h"
8 #include "type.h" 8 #include "type.h"
9 #include "typekind.h" 9 #include "typekind.h"
10 #include "malloc.h" 10 #include "malloc.h"
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 468 }
469 ret = e; 469 ret = e;
470 } 470 }
471 471
472 func assertE2E2(inter *InterfaceType, e Eface) (ret Eface, ok bool) { 472 func assertE2E2(inter *InterfaceType, e Eface) (ret Eface, ok bool) {
473 USED(inter); 473 USED(inter);
474 ret = e; 474 ret = e;
475 ok = e.type != nil; 475 ok = e.type != nil;
476 } 476 }
477 477
478 static uintptr
479 ifacehash1(void *data, Type *t, uintptr h)
480 {
481 Alg *alg;
482 uintptr size;
483 Eface err;
484
485 if(t == nil)
486 return 0;
487
488 alg = t->alg;
489 size = t->size;
490 if(alg->hash->fn == (void(*)())runtime·nohash) {
491 // calling nohash will panic too,
492 // but we can print a better error.
493 runtime·newErrorString(runtime·catstring(runtime·gostringnocopy( (byte*)"hash of unhashable type "), *t->string), &err);
494 runtime·panic(err);
495 }
496 if(size <= sizeof(data))
497 return ((uintptr(*)(void**,uintptr,uintptr))alg->hash)(&data, si ze, h);
498 else
499 return ((uintptr(*)(void*,uintptr,uintptr))alg->hash)(data, size , h);
500 }
501
502 uintptr
503 runtime·ifacehash(Iface a, uintptr h)
504 {
505 if(a.tab == nil)
506 return h;
507 return ifacehash1(a.data, a.tab->type, h);
508 }
509
510 uintptr
511 runtime·efacehash(Eface a, uintptr h)
512 {
513 return ifacehash1(a.data, a.type, h);
514 }
515
516 static bool 478 static bool
517 ifaceeq1(void *data1, void *data2, Type *t) 479 ifaceeq1(void *data1, void *data2, Type *t)
518 { 480 {
519 uintptr size; 481 uintptr size;
520 Alg *alg; 482 Alg *alg;
521 Eface err; 483 Eface err;
522 bool eq; 484 bool eq;
523 485
524 alg = t->alg; 486 alg = t->alg;
525 size = t->size; 487 size = t->size;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 ret = runtime·cnewarray(t, n); 564 ret = runtime·cnewarray(t, n);
603 } 565 }
604 566
605 func reflect·typelinks() (ret Slice) { 567 func reflect·typelinks() (ret Slice) {
606 extern Type *typelink[], *etypelink[]; 568 extern Type *typelink[], *etypelink[];
607 static int32 first = 1; 569 static int32 first = 1;
608 ret.array = (byte*)typelink; 570 ret.array = (byte*)typelink;
609 ret.len = etypelink - typelink; 571 ret.len = etypelink - typelink;
610 ret.cap = ret.len; 572 ret.cap = ret.len;
611 } 573 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b