From: Dmitriy Vyukov Date: Fri, 24 Jan 2014 18:29:01 +0000 (+0400) Subject: runtime: do not zero terminate strings X-Git-Tag: go1.3beta1~876 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9fa9613e0b63b47a1d19c1ba50a7118304dcebae;p=gostls13.git runtime: do not zero terminate strings On top of "tiny allocator" (cl/38750047), reduces number of allocs by 1% on json. No code must rely on zero termination. So will also make debugging simpler, by uncovering issues earlier. json-1 allocated 7949686 7915766 -0.43% allocs 93778 92790 -1.05% time 100957795 97250949 -3.67% rest of the metrics are too noisy. LGTM=r R=golang-codereviews, r, bradfitz, iant CC=golang-codereviews https://golang.org/cl/40370061 --- diff --git a/src/pkg/runtime/string.goc b/src/pkg/runtime/string.goc index 57b3546c3f..8eff05a843 100644 --- a/src/pkg/runtime/string.goc +++ b/src/pkg/runtime/string.goc @@ -46,10 +46,8 @@ 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, 0, FlagNoScan|FlagNoZero); + s.str = runtime·mallocgc(l, 0, FlagNoScan|FlagNoZero); s.len = l; - s.str[l] = 0; for(;;) { ms = runtime·maxstring; if((uintptr)l <= ms || runtime·casp((void**)&runtime·maxstring, (void*)ms, (void*)l))