From e6603ce511a8b1169e135805dbb5e33119451f9e Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 16 Nov 2023 20:36:26 +0100 Subject: [PATCH] Revert "fix sorting for iterables that define copymutable (#52086)" This reverts commit f99e6bfe19b7b8d73975f5f96e54052e9725f1c8. --- base/sort.jl | 4 ++-- test/sorting.jl | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/base/sort.jl b/base/sort.jl index f35add7a55b35..63014f6aa6a44 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -1501,7 +1501,7 @@ function sort(v; kws...) size = IteratorSize(v) size == HasShape{0}() && throw(ArgumentError("$v cannot be sorted")) size == IsInfinite() && throw(ArgumentError("infinite iterator $v cannot be sorted")) - sort!(collect(v); kws...) + sort!(copymutable(v); kws...) end sort(v::AbstractVector; kws...) = sort!(copymutable(v); kws...) # for method disambiguation sort(::AbstractString; kws...) = @@ -1513,7 +1513,7 @@ function sort(x::NTuple{N}; lt::Function=isless, by::Function=identity, rev::Union{Bool,Nothing}=nothing, order::Ordering=Forward) where N o = ord(lt,by,rev,order) if N > 9 - v = sort!(collect(x), DEFAULT_STABLE, o) + v = sort!(copymutable(x), DEFAULT_STABLE, o) tuple((v[i] for i in 1:N)...) else _sort(x, o) diff --git a/test/sorting.jl b/test/sorting.jl index 9cb5d717635c9..1164f2932d880 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -559,11 +559,6 @@ end @test_throws ArgumentError sort("string") @test_throws ArgumentError("1 cannot be sorted") sort(1) - - @test sort(Set((1, 3, 6))) == [1, 3, 6] - @test sort(Dict((1=>9, 3=>2, 6=>5))) == [1=>9, 3=>2, 6=>5] - @test sort(keys(Dict((1=>2, 3=>5, 6=>9)))) == [1, 3, 6] - @test sort(values(Dict((1=>9, 3=>2, 6=>5)))) == [2, 5, 9] end @testset "sort!(::AbstractVector{<:Integer}) with short int range" begin