diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2018-04-20 10:22:54 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2018-04-21 01:05:32 +0000 |
commit | 37dd7cd040e626d5a9c30f2880005643b3a23d22 (patch) | |
tree | 1dec57295c369c316c13e0cb2108e6c040f7eaef /src/runtime/slice.go | |
parent | 566e3e074c089568412a44a8d315c2881cfd8e8f (diff) | |
download | go-37dd7cd040e626d5a9c30f2880005643b3a23d22.tar.gz go-37dd7cd040e626d5a9c30f2880005643b3a23d22.zip |
runtime: use sys.PtrSize in growslice
Minor cleanup.
Change-Id: I4175de392969bb6408081a75cebdaeadcef1e68c
Reviewed-on: https://go-review.googlesource.com/108576
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/slice.go')
-rw-r--r-- | src/runtime/slice.go | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go index 0924d1d8e6..40c5995153 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -128,10 +128,9 @@ func growslice(et *_type, old slice, cap int) slice { var overflow bool var lenmem, newlenmem, capmem uintptr - const ptrSize = unsafe.Sizeof((*byte)(nil)) // Specialize for common values of et.size. // For 1 we don't need any division/multiplication. - // For ptrSize, compiler will optimize division/multiplication into a shift by a constant. + // For sys.PtrSize, compiler will optimize division/multiplication into a shift by a constant. // For powers of 2, use a variable shift. switch { case et.size == 1: @@ -140,15 +139,15 @@ func growslice(et *_type, old slice, cap int) slice { capmem = roundupsize(uintptr(newcap)) overflow = uintptr(newcap) > maxAlloc newcap = int(capmem) - case et.size == ptrSize: - lenmem = uintptr(old.len) * ptrSize - newlenmem = uintptr(cap) * ptrSize - capmem = roundupsize(uintptr(newcap) * ptrSize) - overflow = uintptr(newcap) > maxAlloc/ptrSize - newcap = int(capmem / ptrSize) + case et.size == sys.PtrSize: + lenmem = uintptr(old.len) * sys.PtrSize + newlenmem = uintptr(cap) * sys.PtrSize + capmem = roundupsize(uintptr(newcap) * sys.PtrSize) + overflow = uintptr(newcap) > maxAlloc/sys.PtrSize + newcap = int(capmem / sys.PtrSize) case isPowerOfTwo(et.size): var shift uintptr - if ptrSize == 8 { + if sys.PtrSize == 8 { // Mask shift for better code generation. shift = uintptr(sys.Ctz64(uint64(et.size))) & 63 } else { |