Commit 37dd7cd0 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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: default avatarIan Lance Taylor <iant@golang.org>
parent 566e3e07
...@@ -128,10 +128,9 @@ func growslice(et *_type, old slice, cap int) slice { ...@@ -128,10 +128,9 @@ func growslice(et *_type, old slice, cap int) slice {
var overflow bool var overflow bool
var lenmem, newlenmem, capmem uintptr var lenmem, newlenmem, capmem uintptr
const ptrSize = unsafe.Sizeof((*byte)(nil))
// Specialize for common values of et.size. // Specialize for common values of et.size.
// For 1 we don't need any division/multiplication. // 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. // For powers of 2, use a variable shift.
switch { switch {
case et.size == 1: case et.size == 1:
...@@ -140,15 +139,15 @@ func growslice(et *_type, old slice, cap int) slice { ...@@ -140,15 +139,15 @@ func growslice(et *_type, old slice, cap int) slice {
capmem = roundupsize(uintptr(newcap)) capmem = roundupsize(uintptr(newcap))
overflow = uintptr(newcap) > maxAlloc overflow = uintptr(newcap) > maxAlloc
newcap = int(capmem) newcap = int(capmem)
case et.size == ptrSize: case et.size == sys.PtrSize:
lenmem = uintptr(old.len) * ptrSize lenmem = uintptr(old.len) * sys.PtrSize
newlenmem = uintptr(cap) * ptrSize newlenmem = uintptr(cap) * sys.PtrSize
capmem = roundupsize(uintptr(newcap) * ptrSize) capmem = roundupsize(uintptr(newcap) * sys.PtrSize)
overflow = uintptr(newcap) > maxAlloc/ptrSize overflow = uintptr(newcap) > maxAlloc/sys.PtrSize
newcap = int(capmem / ptrSize) newcap = int(capmem / sys.PtrSize)
case isPowerOfTwo(et.size): case isPowerOfTwo(et.size):
var shift uintptr var shift uintptr
if ptrSize == 8 { if sys.PtrSize == 8 {
// Mask shift for better code generation. // Mask shift for better code generation.
shift = uintptr(sys.Ctz64(uint64(et.size))) & 63 shift = uintptr(sys.Ctz64(uint64(et.size))) & 63
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment