@@ -904,6 +904,8 @@ julia> push!([1, 2, 3], 4, 5, 6)
904
904
If `collection` is ordered, use [`append!`](@ref) to add all the elements of another
905
905
collection to it. The result of the preceding example is equivalent to `append!([1, 2, 3], [4,
906
906
5, 6])`. For `AbstractSet` objects, [`union!`](@ref) can be used instead.
907
+
908
+ See [`sizehint!`](@ref) for notes about the performance model.
907
909
"""
908
910
function push! end
909
911
@@ -951,6 +953,8 @@ julia> append!([1, 2, 3], [4, 5], [6])
951
953
Use [`push!`](@ref) to add individual items to `collection` which are not already
952
954
themselves in another collection. The result of the preceding example is equivalent to
953
955
`push!([1, 2, 3], 4, 5, 6)`.
956
+
957
+ See [`sizehint!`](@ref) for notes about the performance model.
954
958
"""
955
959
function append! (a:: Vector , items:: AbstractVector )
956
960
itemindices = eachindex (items)
@@ -1097,6 +1101,19 @@ end
1097
1101
sizehint!(s, n)
1098
1102
1099
1103
Suggest that collection `s` reserve capacity for at least `n` elements. This can improve performance.
1104
+
1105
+ # Notes on the performance model
1106
+
1107
+ For types that support `sizehint!`,
1108
+
1109
+ 1. `push!` and `append!` methods generally may (but are not required to) preallocate extra
1110
+ storage. For types implemented in `Base`, they typically do, using a heuristic optimized for
1111
+ a general use case.
1112
+
1113
+ 2. `sizehint!` may control this preallocation. Again, it typically does this for types in
1114
+ `Base`.
1115
+
1116
+ 3. `empty!` is nearly costless (and O(1)) for types that support this kind of preallocation.
1100
1117
"""
1101
1118
function sizehint! end
1102
1119
0 commit comments