Skip to content

Commit 37dd7cd

Browse files
committed
runtime: use sys.PtrSize in growslice
Minor cleanup. Change-Id: I4175de392969bb6408081a75cebdaeadcef1e68c Reviewed-on: https://go-review.googlesource.com/108576 Run-TryBot: Josh Bleecher Snyder <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 566e3e0 commit 37dd7cd

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/runtime/slice.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ func growslice(et *_type, old slice, cap int) slice {
128128

129129
var overflow bool
130130
var lenmem, newlenmem, capmem uintptr
131-
const ptrSize = unsafe.Sizeof((*byte)(nil))
132131
// Specialize for common values of et.size.
133132
// For 1 we don't need any division/multiplication.
134-
// For ptrSize, compiler will optimize division/multiplication into a shift by a constant.
133+
// For sys.PtrSize, compiler will optimize division/multiplication into a shift by a constant.
135134
// For powers of 2, use a variable shift.
136135
switch {
137136
case et.size == 1:
@@ -140,15 +139,15 @@ func growslice(et *_type, old slice, cap int) slice {
140139
capmem = roundupsize(uintptr(newcap))
141140
overflow = uintptr(newcap) > maxAlloc
142141
newcap = int(capmem)
143-
case et.size == ptrSize:
144-
lenmem = uintptr(old.len) * ptrSize
145-
newlenmem = uintptr(cap) * ptrSize
146-
capmem = roundupsize(uintptr(newcap) * ptrSize)
147-
overflow = uintptr(newcap) > maxAlloc/ptrSize
148-
newcap = int(capmem / ptrSize)
142+
case et.size == sys.PtrSize:
143+
lenmem = uintptr(old.len) * sys.PtrSize
144+
newlenmem = uintptr(cap) * sys.PtrSize
145+
capmem = roundupsize(uintptr(newcap) * sys.PtrSize)
146+
overflow = uintptr(newcap) > maxAlloc/sys.PtrSize
147+
newcap = int(capmem / sys.PtrSize)
149148
case isPowerOfTwo(et.size):
150149
var shift uintptr
151-
if ptrSize == 8 {
150+
if sys.PtrSize == 8 {
152151
// Mask shift for better code generation.
153152
shift = uintptr(sys.Ctz64(uint64(et.size))) & 63
154153
} else {

0 commit comments

Comments
 (0)