From b343e7c50d9062b3bc3e6f6f1d0ff47bc1aedeb9 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Tue, 10 Jan 2017 13:15:22 +0000 Subject: [PATCH 1/3] remove `subtypes` search for concrete types This prevents an unnecessary/expensive call to `_subtypes` when `subtypes` is called on a concrete type. --- base/reflection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/reflection.jl b/base/reflection.jl index dbf5b50a7179e..1f5e3aec2e62e 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -301,7 +301,7 @@ function _subtypes(m::Module, x::DataType, sts=Set{DataType}(), visited=Set{Modu end return sts end -subtypes(m::Module, x::DataType) = sort(collect(_subtypes(m, x)), by=string) +subtypes(m::Module, x::DataType) = x.abstract ? sort(collect(_subtypes(m, x)), by=string) : DataType[] """ subtypes(T::DataType) From 2dd035804de47ced34fd04c173de9478515568b2 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Tue, 10 Jan 2017 17:05:32 +0000 Subject: [PATCH 2/3] in place sort --- base/reflection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/reflection.jl b/base/reflection.jl index 1f5e3aec2e62e..c843e5825e6e9 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -301,7 +301,7 @@ function _subtypes(m::Module, x::DataType, sts=Set{DataType}(), visited=Set{Modu end return sts end -subtypes(m::Module, x::DataType) = x.abstract ? sort(collect(_subtypes(m, x)), by=string) : DataType[] +subtypes(m::Module, x::DataType) = x.abstract ? sort!(collect(_subtypes(m, x)), by=string) : DataType[] """ subtypes(T::DataType) From a311691e75f630e997d1f439e8eea4bc901a9bc8 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Thu, 26 Jan 2017 07:52:59 +0000 Subject: [PATCH 3/3] add tes --- test/reflection.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/reflection.jl b/test/reflection.jl index d7c1493b31709..1f7d31b4ae304 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -610,3 +610,6 @@ end @generated f18883() = nothing @test !isempty(sprint(io->code_llvm(io, f18883, Tuple{}))) @test !isempty(sprint(io->code_native(io, f18883, Tuple{}))) + +# PR #19964 +@test isempty(subtypes(Float64))