diff options
| author | Marvin Stenger <marvin.stenger94@gmail.com> | 2016-03-24 01:55:42 +0100 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2016-03-24 18:17:28 +0000 |
| commit | 44532f1a9defb9cc4f48e74a7fa1ffd1dfa67022 (patch) | |
| tree | 7d10149d6a598cee1b1f9a74e35a602c2b274e65 /src/runtime | |
| parent | f045ca8d45c1f06312a022e40677eec3fc2e0ed3 (diff) | |
| download | go-44532f1a9defb9cc4f48e74a7fa1ffd1dfa67022.tar.xz | |
runtime: fix inconsistency in slice.go
Fixes #14938.
Additionally some simplifications along the way.
Change-Id: I2c5fb7e32dcc6fab68fff36a49cb72e715756abe
Reviewed-on: https://go-review.googlesource.com/21046
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/slice.go | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go index 5e88ed9453..d35ecadb16 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -62,23 +62,20 @@ func growslice(t *slicetype, old slice, cap int) slice { } newcap := old.cap - if newcap+newcap < cap { + doublecap := newcap + newcap + if cap > doublecap { newcap = cap } else { - for { - if old.len < 1024 { - newcap += newcap - } else { + if old.len < 1024 { + newcap = doublecap + } else { + for newcap < cap { 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 |
