File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,14 @@ func small(i int) string {
174174 return smalls [i * 2 : i * 2 + 2 ]
175175}
176176
177+ // RuntimeFormatBase10 formats u into the tail of a
178+ // and returns the offset to the first byte written to a.
179+ // It is only for use by package runtime.
180+ // Other packages should use AppendUint.
181+ func RuntimeFormatBase10 (a []byte , u uint64 ) int {
182+ return formatBase10 (a , u )
183+ }
184+
177185// formatBase10 formats the decimal representation of u into the tail of a
178186// and returns the offset of the first byte written to a. That is, after
179187//
Original file line number Diff line number Diff line change @@ -140,13 +140,32 @@ func printcomplex64(c complex64) {
140140}
141141
142142func printuint (v uint64 ) {
143+ // Note: Avoiding strconv.AppendUint so that it's clearer
144+ // that there are no allocations in this routine.
145+ // cmd/link/internal/ld.TestAbstractOriginSanity
146+ // sees the append and doesn't realize it doesn't allocate.
143147 var buf [20 ]byte
144- gwrite (strconv .AppendUint (buf [:0 ], v , 10 ))
148+ i := strconv .RuntimeFormatBase10 (buf [:], v )
149+ gwrite (buf [i :])
145150}
146151
147152func printint (v int64 ) {
153+ // Note: Avoiding strconv.AppendUint so that it's clearer
154+ // that there are no allocations in this routine.
155+ // cmd/link/internal/ld.TestAbstractOriginSanity
156+ // sees the append and doesn't realize it doesn't allocate.
157+ neg := v < 0
158+ u := uint64 (v )
159+ if neg {
160+ u = - u
161+ }
148162 var buf [20 ]byte
149- gwrite (strconv .AppendInt (buf [:0 ], v , 10 ))
163+ i := strconv .RuntimeFormatBase10 (buf [:], u )
164+ if neg {
165+ i --
166+ buf [i ] = '-'
167+ }
168+ gwrite (buf [i :])
150169}
151170
152171var minhexdigits = 0 // protected by printlock
You can’t perform that action at this time.
0 commit comments