From 05001a0f0a7bfae6a8bab381ebae1c17594cd5a5 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Sat, 18 Sep 2021 13:15:55 +0200 Subject: [PATCH] specialize `hastypemax` on `Bool` Since `Bool` is not included in `Base.BitIntegerType`, `hastypemax(Bool)` falls back to the slow generic version. This reduces the performance of `digits!` with Boolean target vector (for `base=2`) significantly. Specializing `hastypemax` on `Bool` fixes this performance bug. In one of my applications, where `digits!` should only take a small fraction of the total runtime, fixing this improves the performance by more than 10%. --- base/intfuncs.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 169bbe313a620..6e8def9e5c308 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -882,6 +882,7 @@ end Return true if and only if the extrema `typemax(T)` and `typemin(T)` are defined. """ hastypemax(::Base.BitIntegerType) = true +hastypemax(::Type{Bool}) = true hastypemax(::Type{T}) where {T} = applicable(typemax, T) && applicable(typemin, T) """