aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2025-11-03 15:35:26 -0500
committerRuss Cox <rsc@golang.org>2025-11-03 16:37:04 -0800
commite2c6a2024c9bdd56786feef42a2e2c5c5adeced2 (patch)
treeb88583fe99d40ef0928dbef97c2b4ed378a22311 /src/runtime
parentc93cc603cd5c731d00dc019c94490edca6160841 (diff)
downloadgo-e2c6a2024c9bdd56786feef42a2e2c5c5adeced2.tar.xz
runtime: avoid append in printint, printuint
Should make cmd/link/internal/ld.TestAbstractOriginSanity happier. Change-Id: I121927d42e527ff23d996e7387066f149b11cc59 Reviewed-on: https://go-review.googlesource.com/c/go/+/717480 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/print.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/runtime/print.go b/src/runtime/print.go
index e32ecb9450..c01db9d7f9 100644
--- a/src/runtime/print.go
+++ b/src/runtime/print.go
@@ -140,13 +140,32 @@ func printcomplex64(c complex64) {
}
func printuint(v uint64) {
+ // Note: Avoiding strconv.AppendUint so that it's clearer
+ // that there are no allocations in this routine.
+ // cmd/link/internal/ld.TestAbstractOriginSanity
+ // sees the append and doesn't realize it doesn't allocate.
var buf [20]byte
- gwrite(strconv.AppendUint(buf[:0], v, 10))
+ i := strconv.RuntimeFormatBase10(buf[:], v)
+ gwrite(buf[i:])
}
func printint(v int64) {
+ // Note: Avoiding strconv.AppendUint so that it's clearer
+ // that there are no allocations in this routine.
+ // cmd/link/internal/ld.TestAbstractOriginSanity
+ // sees the append and doesn't realize it doesn't allocate.
+ neg := v < 0
+ u := uint64(v)
+ if neg {
+ u = -u
+ }
var buf [20]byte
- gwrite(strconv.AppendInt(buf[:0], v, 10))
+ i := strconv.RuntimeFormatBase10(buf[:], u)
+ if neg {
+ i--
+ buf[i] = '-'
+ }
+ gwrite(buf[i:])
}
var minhexdigits = 0 // protected by printlock