aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/slice.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-12-04 21:44:05 -0800
committerRuss Cox <rsc@golang.org>2009-12-04 21:44:05 -0800
commit864c757a1cff01f57ff415229674bcf8f701836c (patch)
tree99d2cd8c0f28e98a43598373139956cc402c9fa0 /src/pkg/runtime/slice.c
parent6f14cada11411c6fff924c0ab8d8bbd430c3ae61 (diff)
downloadgo-864c757a1cff01f57ff415229674bcf8f701836c.tar.xz
gc/runtime: pass type structure to makeslice.
* inform garbage collector about memory with no pointers in it 1.9s gcc reverse-complement.c reverse-complement.go 4.5s / 3.5s original, with/without bounds checks 3.5s / 3.3s bounds check reduction 3.3s / 2.8s smarter garbage collector 2.6s / 2.3s assembler bytes.IndexByte 2.5s / 2.1s even smarter garbage collector (this CL) R=r https://golang.org/cl/165064
Diffstat (limited to 'src/pkg/runtime/slice.c')
-rw-r--r--src/pkg/runtime/slice.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c
index 17762ae269..d5e524e8a4 100644
--- a/src/pkg/runtime/slice.c
+++ b/src/pkg/runtime/slice.c
@@ -3,35 +3,35 @@
// license that can be found in the LICENSE file.
#include "runtime.h"
+#include "type.h"
+#include "malloc.h"
static int32 debug = 0;
-// makeslice(nel int, cap int, width int) (ary []any);
+// makeslice(typ *Type, nel int, cap int) (ary []any);
void
-runtime·makeslice(uint32 nel, uint32 cap, uint32 width, Slice ret)
+runtime·makeslice(SliceType *t, uint32 nel, uint32 cap, Slice ret)
{
uint64 size;
if(cap < nel)
cap = nel;
- size = cap*width;
+ size = cap*t->elem->size;
ret.len = nel;
ret.cap = cap;
- ret.array = mal(size);
+
+ if(t->elem->kind&KindNoPointers)
+ ret.array = mallocgc(size, RefNoPointers, 1);
+ else
+ ret.array = mal(size);
FLUSH(&ret);
if(debug) {
- prints("makeslice: nel=");
- runtime·printint(nel);
- prints("; cap=");
- runtime·printint(cap);
- prints("; width=");
- runtime·printint(width);
- prints("; ret=");
- runtime·printslice(ret);
- prints("\n");
+ printf("makeslice(%S, %d, %d); ret=",
+ *t->string, nel, cap);
+ runtime·printslice(ret);
}
}