Skip to content

Commit 61c1425

Browse files
committed
reflect: Always call sliceGrow() in extendSlice()
sliceGrow() will return the old slice if its capacity is large enough. Signed-off-by: L. Pereira <[email protected]>
1 parent a8c7dcf commit 61c1425

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

src/reflect/value.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,18 +1712,7 @@ func extendSlice(v Value, n int) sliceHeader {
17121712
old = *(*sliceHeader)(v.value)
17131713
}
17141714

1715-
var nbuf unsafe.Pointer
1716-
var nlen, ncap uintptr
1717-
1718-
if old.len+uintptr(n) > old.cap {
1719-
// we need to grow the slice
1720-
nbuf, nlen, ncap = sliceGrow(old.data, old.len, old.cap, old.cap+uintptr(n), v.typecode.elem().Size())
1721-
} else {
1722-
// we can reuse the slice we have
1723-
nbuf = old.data
1724-
nlen = old.len
1725-
ncap = old.cap
1726-
}
1715+
nbuf, nlen, ncap := sliceGrow(old.data, old.len, old.cap, old.len+uintptr(n), v.typecode.elem().Size())
17271716

17281717
return sliceHeader{
17291718
data: nbuf,

0 commit comments

Comments
 (0)