From 3accfe8c80eb7165a11f86ab18824f0045bafe3e Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Mon, 11 Dec 2023 18:16:48 +0100 Subject: [PATCH] Improve `sizehint!` docstring about `shrink` arg (#52226) See https://github.com/JuliaLang/julia/pull/51929#discussion_r1390444453. --- base/array.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/base/array.jl b/base/array.jl index 6fd6f61a4fc95..beb5246a0cbda 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1441,10 +1441,14 @@ you expect that you're going to have to push a lot of values onto `s`, you can a the cost of incremental reallocation by doing it once up front; this can improve performance. -If `first` is true, then the reserved space is from the start of the collection, for ordered -collections. Supplying this keyword may result in an error if the collection is nor ordered +If `first` is `true`, then any additional space is reserved before the start of the collection. +This way, subsequent calls to `pushfirst!` (instead of `push!`) may become faster. +Supplying this keyword may result in an error if the collection is not ordered or if `pushfirst!` is not supported for this collection. +If `shrink=true` (the default), the collection's capacity may be reduced if its current +capacity is greater than `n`. + See also [`resize!`](@ref). # Notes on the performance model @@ -1460,8 +1464,6 @@ For types that support `sizehint!`, 3. `empty!` is nearly costless (and O(1)) for types that support this kind of preallocation. -4. `shrink` controls if the collection can be shrunk. - !!! compat "Julia 1.11" The `shrink` and `first` arguments were added in Julia 1.11. """