runtime: avoid append in printint, printuint
Should make cmd/link/internal/ld.TestAbstractOriginSanity happier.
diff --git a/src/internal/strconv/itoa.go b/src/internal/strconv/itoa.go
index d06de47..2375e03 100644
--- a/src/internal/strconv/itoa.go
+++ b/src/internal/strconv/itoa.go
@@ -174,6 +174,14 @@
return smalls[i*2 : i*2+2]
}
+// RuntimeFormatBase10 formats u into the tail of a
+// and returns the offset to the first byte written to a.
+// It is only for use by package runtime.
+// Other packages should use AppendUint.
+func RuntimeFormatBase10(a []byte, u uint64) int {
+ return formatBase10(a, u)
+}
+
// formatBase10 formats the decimal representation of u into the tail of a
// and returns the offset of the first byte written to a. That is, after
//
diff --git a/src/runtime/print.go b/src/runtime/print.go
index e32ecb9..c01db9d 100644
--- a/src/runtime/print.go
+++ b/src/runtime/print.go
@@ -140,13 +140,32 @@
}
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
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
Hmm, the longtest trybot failure is now complaining about castogstatus "calling" panic, which happens here:
print("runtime: castogscanstatus oldval=", hex(oldval), " newval=", hex(newval), "\n")
throw("castogscanstatus")
panic("not reached")That "panic" has been there since 2015.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hmm, the longtest trybot failure is now complaining about castogstatus "calling" panic, which happens here:
print("runtime: castogscanstatus oldval=", hex(oldval), " newval=", hex(newval), "\n")
throw("castogscanstatus")
panic("not reached")That "panic" has been there since 2015.
CL 717406 fixed this one. Maybe now strconv is the only one left.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
runtime: avoid append in printint, printuint
Should make cmd/link/internal/ld.TestAbstractOriginSanity happier.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |