Commit 44532f1a authored by Marvin Stenger's avatar Marvin Stenger Committed by Ian Lance Taylor

runtime: fix inconsistency in slice.go

Fixes #14938.

Additionally some simplifications along the way.

Change-Id: I2c5fb7e32dcc6fab68fff36a49cb72e715756abe
Reviewed-on: https://go-review.googlesource.com/21046Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
parent f045ca8d
...@@ -62,23 +62,20 @@ func growslice(t *slicetype, old slice, cap int) slice { ...@@ -62,23 +62,20 @@ func growslice(t *slicetype, old slice, cap int) slice {
} }
newcap := old.cap newcap := old.cap
if newcap+newcap < cap { doublecap := newcap + newcap
if cap > doublecap {
newcap = cap newcap = cap
} else { } else {
for { if old.len < 1024 {
if old.len < 1024 { newcap = doublecap
newcap += newcap } else {
} else { for newcap < cap {
newcap += newcap / 4 newcap += newcap / 4
} }
if newcap >= cap {
break
}
} }
} if uintptr(newcap) > maxcap {
panic(errorString("growslice: cap out of range"))
if uintptr(newcap) >= maxcap { }
panic(errorString("growslice: cap out of range"))
} }
lenmem := uintptr(old.len) * et.size lenmem := uintptr(old.len) * et.size
......
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