Skip to content

Commit 2a6ee53

Browse files
committed
Add shrinkage control for Vector
1 parent c94e80a commit 2a6ee53

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

base/array.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,8 +1467,7 @@ For types that support `sizehint!`,
14671467
"""
14681468
function sizehint! end
14691469

1470-
function sizehint!(a::Vector, sz::Integer)
1471-
# TODO - controll shrinkage
1470+
function sizehint!(a::Vector, sz::Integer; shrink = true)
14721471
len = length(a)
14731472
ref = a.ref
14741473
mem = ref.mem
@@ -1477,7 +1476,7 @@ function sizehint!(a::Vector, sz::Integer)
14771476
sz = max(Int(sz), offset + len - 1)
14781477
if sz <= memlen
14791478
# if we don't save at least 1/8th memlen then its not worth it to shrink
1480-
if memlen - sz <= div(memlen, 8)
1479+
if !shrink || memlen - sz <= div(memlen, 8)
14811480
return a
14821481
end
14831482
newmem = array_new_memory(mem, sz)

0 commit comments

Comments
 (0)