]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't allocate a new string in printf
authorKeith Randall <khr@golang.org>
Fri, 29 Aug 2014 06:26:50 +0000 (23:26 -0700)
committerKeith Randall <khr@golang.org>
Fri, 29 Aug 2014 06:26:50 +0000 (23:26 -0700)
LGTM=dave
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/139890043

src/pkg/runtime/print1.go
src/pkg/runtime/string.c
src/pkg/runtime/stubs.go

index 94ba9e47332370963ff42c9b35551ea31781a82d..9df6a621bb144459a6c3958a3d9df5158fac11c4 100644 (file)
@@ -39,7 +39,7 @@ func goprintf(s string) {
 // and type tables.
 //go:nosplit
 func printf(s *byte) {
-       vprintf(gostring(s), add(unsafe.Pointer(&s), unsafe.Sizeof(s)))
+       vprintf(gostringnocopy(s), add(unsafe.Pointer(&s), unsafe.Sizeof(s)))
 }
 
 // sprintf is only called from C code.
index 60a0545a9a5a964a2ee6f5b3e0c4af0d17cb2a6a..5421b531962a568d14ae9080ebf334efad2453d8 100644 (file)
@@ -90,6 +90,7 @@ runtime·gobytes(byte *p, intgo n)
        return sl;
 }
 
+#pragma textflag NOSPLIT
 String
 runtime·gostringnocopy(byte *str)
 {
index 26126fcf9a49adcdad571add4fe3fdf49c6aa6a1..2014dfbf909dead98f6deb08eabffafcaff4b53c 100644 (file)
@@ -203,6 +203,7 @@ func noteclear(n *note)
 func lock(lk *mutex)
 func unlock(lk *mutex)
 func purgecachedstats(c *mcache)
+func gostringnocopy(b *byte) string
 
 //go:noescape
 func write(fd uintptr, p unsafe.Pointer, n int32) int32