Skip to content

Commit f2c2837

Browse files
authored
Don't call sort! and partialsort! "in-place" (#58901)
"in-place" strongly implies non-allocating. This docs change removes that language from the `sort!` and `sortperm!` docstrings because those functions do sometimes allocate.
1 parent f356a40 commit f2c2837

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

base/sort.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ maybeview(v, k::Integer) = v[k]
115115
"""
116116
partialsort!(v, k; by=identity, lt=isless, rev=false)
117117
118-
Partially sort the vector `v` in place so that the value at index `k` (or
118+
Mutate the vector `v` so that the value at index `k` (or
119119
range of adjacent values if `k` is a range) occurs
120120
at the position where it would appear if the array were fully sorted. If `k` is a single
121121
index, that value is returned; if `k` is a range, an array of values at those indices is
@@ -1625,10 +1625,11 @@ defalg(v) = DEFAULT_STABLE
16251625
"""
16261626
sort!(v; alg::Base.Sort.Algorithm=Base.Sort.defalg(v), lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward)
16271627
1628-
Sort the vector `v` in place. A stable algorithm is used by default: the
1629-
ordering of elements that compare equal is preserved. A specific algorithm can
1630-
be selected via the `alg` keyword (see [Sorting Algorithms](@ref) for available
1631-
algorithms).
1628+
Mutate the vector `v` so that it is sorted.
1629+
1630+
A stable algorithm is used by default: the ordering of elements that
1631+
compare equal is preserved. A specific algorithm can be selected via the
1632+
`alg` keyword (see [Sorting Algorithms](@ref) for available algorithms).
16321633
16331634
Elements are first transformed with the function `by` and then compared
16341635
according to either the function `lt` or the ordering `order`. Finally, the
@@ -1745,7 +1746,7 @@ end
17451746
Variant of [`sort!`](@ref) that returns a sorted copy of `v` leaving `v` itself unmodified.
17461747
17471748
When calling `sort` on the [`keys`](@ref) or [`values](@ref) of a dictionary, `v` is
1748-
collected and then sorted in place.
1749+
collected and then sorted.
17491750
17501751
!!! compat "Julia 1.12"
17511752
Sorting `NTuple`s requires Julia 1.12 or later.
@@ -2289,7 +2290,7 @@ UIntMappable(T::Type, order::ReverseOrdering) = UIntMappable(T, order.fwd)
22892290

22902291
### Vectors
22912292

2292-
# Convert v to unsigned integers in place, maintaining sort order.
2293+
# Convert v to unsigned integers in-place, maintaining sort order.
22932294
function uint_map!(v::AbstractVector, lo::Integer, hi::Integer, order::Ordering)
22942295
u = reinterpret(UIntMappable(eltype(v), order), v)
22952296
@inbounds for i in lo:hi

0 commit comments

Comments
 (0)