From 23f9751e832e47fa3f433485f9c7e93cb7a92817 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Sat, 31 Aug 2013 14:09:34 -0700 Subject: [PATCH] runtime: clean up map code. Remove hashmap.h. Use cnew/cnewarray instead of mallocgc. R=golang-dev, dvyukov CC=golang-dev https://golang.org/cl/13396045 --- src/pkg/runtime/hashmap.c | 19 +++++++++---------- src/pkg/runtime/hashmap.h | 4 ---- src/pkg/runtime/mgc0.c | 1 - 3 files changed, 9 insertions(+), 15 deletions(-) delete mode 100644 src/pkg/runtime/hashmap.h diff --git a/src/pkg/runtime/hashmap.c b/src/pkg/runtime/hashmap.c index 244885be17b..6ff0c32aa43 100644 --- a/src/pkg/runtime/hashmap.c +++ b/src/pkg/runtime/hashmap.c @@ -5,7 +5,6 @@ #include "runtime.h" #include "arch_GOARCH.h" #include "malloc.h" -#include "hashmap.h" #include "type.h" #include "race.h" #include "../../cmd/ld/textflag.h" @@ -255,7 +254,7 @@ hash_init(MapType *t, Hmap *h, uint32 hint) // done lazily later. buckets = nil; } else { - buckets = runtime·mallocgc(bucketsize << B, (uintptr)t->bucket | TypeInfo_Array, 0); + buckets = runtime·cnewarray(t->bucket, (uintptr)1 << B); } // initialize Hmap @@ -317,7 +316,7 @@ evacuate(MapType *t, Hmap *h, uintptr oldbucket) if((hash & newbit) == 0) { if(xi == BUCKETSIZE) { if(checkgc) mstats.next_gc = mstats.heap_alloc; - newx = runtime·mallocgc(h->bucketsize, (uintptr)t->bucket, 0); + newx = runtime·cnew(t->bucket); x->overflow = newx; x = newx; xi = 0; @@ -341,7 +340,7 @@ evacuate(MapType *t, Hmap *h, uintptr oldbucket) } else { if(yi == BUCKETSIZE) { if(checkgc) mstats.next_gc = mstats.heap_alloc; - newy = runtime·mallocgc(h->bucketsize, (uintptr)t->bucket, 0); + newy = runtime·cnew(t->bucket); y->overflow = newy; y = newy; yi = 0; @@ -419,7 +418,7 @@ hash_grow(MapType *t, Hmap *h) old_buckets = h->buckets; // NOTE: this could be a big malloc, but since we don't need zeroing it is probably fast. if(checkgc) mstats.next_gc = mstats.heap_alloc; - new_buckets = runtime·mallocgc((uintptr)h->bucketsize << (h->B + 1), (uintptr)t->bucket | TypeInfo_Array, 0); + new_buckets = runtime·cnewarray(t->bucket, (uintptr)1 << (h->B + 1)); flags = (h->flags & ~(Iterator | OldIterator)); if((h->flags & Iterator) != 0) flags |= OldIterator; @@ -578,7 +577,7 @@ hash_insert(MapType *t, Hmap *h, void *key, void *value) hash = h->hash0; t->key->alg->hash(&hash, t->key->size, key); if(h->buckets == nil) - h->buckets = runtime·mallocgc(h->bucketsize, (uintptr)t->bucket | TypeInfo_Array, 0); + h->buckets = runtime·cnewarray(t->bucket, 1); again: bucket = hash & (((uintptr)1 << h->B) - 1); @@ -625,7 +624,7 @@ hash_insert(MapType *t, Hmap *h, void *key, void *value) if(inserti == nil) { // all current buckets are full, allocate a new one. if(checkgc) mstats.next_gc = mstats.heap_alloc; - newb = runtime·mallocgc(h->bucketsize, (uintptr)t->bucket, 0); + newb = runtime·cnew(t->bucket); b->overflow = newb; inserti = newb->tophash; insertk = newb->data; @@ -635,13 +634,13 @@ hash_insert(MapType *t, Hmap *h, void *key, void *value) // store new key/value at insert position if((h->flags & IndirectKey) != 0) { if(checkgc) mstats.next_gc = mstats.heap_alloc; - kmem = runtime·mallocgc(t->key->size, (uintptr)t->key, 0); + kmem = runtime·cnew(t->key); *(byte**)insertk = kmem; insertk = kmem; } if((h->flags & IndirectValue) != 0) { if(checkgc) mstats.next_gc = mstats.heap_alloc; - vmem = runtime·mallocgc(t->elem->size, (uintptr)t->elem, 0); + vmem = runtime·cnew(t->elem); *(byte**)insertv = vmem; insertv = vmem; } @@ -929,7 +928,7 @@ runtime·makemap_c(MapType *typ, int64 hint) if(key->alg->hash == runtime·nohash) runtime·throw("runtime.makemap: unsupported map key type"); - h = runtime·mallocgc(sizeof(*h), (uintptr)typ->hmap, 0); + h = runtime·cnew(typ->hmap); hash_init(typ, h, hint); // these calculations are compiler dependent. diff --git a/src/pkg/runtime/hashmap.h b/src/pkg/runtime/hashmap.h deleted file mode 100644 index 024018d5a4f..00000000000 --- a/src/pkg/runtime/hashmap.h +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index 045202915eb..074e756b071 100644 --- a/src/pkg/runtime/mgc0.c +++ b/src/pkg/runtime/mgc0.c @@ -12,7 +12,6 @@ #include "race.h" #include "type.h" #include "typekind.h" -#include "hashmap.h" #include "funcdata.h" #include "../../cmd/ld/textflag.h"