From 8f73286275508a89cf643f58ec4fc4273e8c88f4 Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Thu, 5 Jul 2018 20:35:47 +0200 Subject: [PATCH] Use generic fallback for arrays with !(eltype >: Missing) --- base/missing.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/base/missing.jl b/base/missing.jl index 4a13586e3654d..38322bee65b1e 100644 --- a/base/missing.jl +++ b/base/missing.jl @@ -190,7 +190,10 @@ function iterate(itr::SkipMissing, state...) end # Optimized mapreduce implementation -mapreduce(f, op, itr::SkipMissing{<:AbstractArray}) = _mapreduce(f, op, IndexStyle(itr.x), itr) +# The generic method is faster when !(eltype(A) >: Missing) since it does not need +# additional loops to identify the two first non-missing values of each block +mapreduce(f, op, itr::SkipMissing{<:AbstractArray}) = + _mapreduce(f, op, IndexStyle(itr.x), eltype(itr.x) >: Missing ? itr : itr.x) function _mapreduce(f, op, ::IndexLinear, itr::SkipMissing{<:AbstractArray}) A = itr.x