From f8a850b250655bd26f5da4cfe7299b4a32be28fa Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Fri, 26 Jul 2013 21:17:24 +0400 Subject: runtime: refactor mallocgc Make it accept type, combine flags. Several reasons for the change: 1. mallocgc and settype must be atomic wrt GC 2. settype is called from only one place now 3. it will help performance (eventually settype functionality must be combined with markallocated) 4. flags are easier to read now (no mallocgc(sz, 0, 1, 0) anymore) R=golang-dev, iant, nightlyone, rsc, dave, khr, bradfitz, r CC=golang-dev https://golang.org/cl/10136043 --- src/pkg/runtime/string.goc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/pkg/runtime/string.goc') diff --git a/src/pkg/runtime/string.goc b/src/pkg/runtime/string.goc index 108487d69d..15d690a921 100644 --- a/src/pkg/runtime/string.goc +++ b/src/pkg/runtime/string.goc @@ -45,7 +45,7 @@ gostringsize(intgo l) if(l == 0) return runtime·emptystring; // leave room for NUL for C runtime (e.g., callers of getenv) - s.str = runtime·mallocgc(l+1, FlagNoPointers, 1, 0); + s.str = runtime·mallocgc(l+1, 0, FlagNoPointers|FlagNoZero); s.len = l; s.str[l] = 0; for(;;) { @@ -83,7 +83,7 @@ runtime·gobytes(byte *p, intgo n) { Slice sl; - sl.array = runtime·mallocgc(n, FlagNoPointers, 1, 0); + sl.array = runtime·mallocgc(n, 0, FlagNoPointers|FlagNoZero); sl.len = n; sl.cap = n; runtime·memmove(sl.array, p, n); @@ -250,7 +250,7 @@ func slicebytetostring(b Slice) (s String) { } func stringtoslicebyte(s String) (b Slice) { - b.array = runtime·mallocgc(s.len, FlagNoPointers, 1, 0); + b.array = runtime·mallocgc(s.len, 0, FlagNoPointers|FlagNoZero); b.len = s.len; b.cap = s.len; runtime·memmove(b.array, s.str, s.len); @@ -299,7 +299,7 @@ func stringtoslicerune(s String) (b Slice) { n++; } - b.array = runtime·mallocgc(n*sizeof(r[0]), FlagNoPointers, 1, 0); + b.array = runtime·mallocgc(n*sizeof(r[0]), 0, FlagNoPointers|FlagNoZero); b.len = n; b.cap = n; p = s.str; -- cgit v1.3