Skip to content

Commit 3accfe8

Browse files
authored
Improve sizehint! docstring about shrink arg (#52226)
See #51929 (comment).
1 parent 456951f commit 3accfe8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

base/array.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,10 +1441,14 @@ you expect that you're going to have to push a lot of values onto `s`, you can a
14411441
the cost of incremental reallocation by doing it once up front; this can improve
14421442
performance.
14431443
1444-
If `first` is true, then the reserved space is from the start of the collection, for ordered
1445-
collections. Supplying this keyword may result in an error if the collection is nor ordered
1444+
If `first` is `true`, then any additional space is reserved before the start of the collection.
1445+
This way, subsequent calls to `pushfirst!` (instead of `push!`) may become faster.
1446+
Supplying this keyword may result in an error if the collection is not ordered
14461447
or if `pushfirst!` is not supported for this collection.
14471448
1449+
If `shrink=true` (the default), the collection's capacity may be reduced if its current
1450+
capacity is greater than `n`.
1451+
14481452
See also [`resize!`](@ref).
14491453
14501454
# Notes on the performance model
@@ -1460,8 +1464,6 @@ For types that support `sizehint!`,
14601464
14611465
3. `empty!` is nearly costless (and O(1)) for types that support this kind of preallocation.
14621466
1463-
4. `shrink` controls if the collection can be shrunk.
1464-
14651467
!!! compat "Julia 1.11"
14661468
The `shrink` and `first` arguments were added in Julia 1.11.
14671469
"""

0 commit comments

Comments
 (0)