Skip to content

Commit

Permalink
Use isa Null instead of isnull() to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Oct 17, 2017
1 parent 65297f9 commit 921d956
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Nulls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Base.done(itr::EachReplaceNull, state) = done(itr.x, state)
Base.eltype(itr::EachReplaceNull) = Nulls.T(eltype(itr.x))
@inline function Base.next(itr::EachReplaceNull, state)
v, s = next(itr.x, state)
((isnull(v) ? itr.replacement : v)::eltype(itr), s)
(v isa Null ? itr.replacement : v, s)
end

"""
Expand Down Expand Up @@ -203,7 +203,7 @@ Base.eltype(itr::EachSkipNull) = Nulls.T(eltype(itr.x))
@inline function Base.start(itr::EachSkipNull)
s = start(itr.x)
v = null
@inbounds while !done(itr.x, s) && isnull(v)
@inbounds while !done(itr.x, s) && v isa Null
v, s = next(itr.x, s)
end
(v, s)
Expand All @@ -212,10 +212,10 @@ end
@inline function Base.next(itr::EachSkipNull, state)
v1, s = state
v2 = null
@inbounds while !done(itr.x, s) && isnull(v2)
@inbounds while !done(itr.x, s) && v2 isa Null
v2, s = next(itr.x, s)
end
(v1::eltype(itr), (v2, s))
(v1, (v2, s))
end
# Optimized implementation for AbstractArray, relying on the ability to access x[i] twice:
# once in done() to find the next non-null entry, and once in next() to return it.
Expand All @@ -224,7 +224,7 @@ end
idx = eachindex(x)
@inbounds while !done(idx, s)
i, new_s = next(idx, s)
isnull(x[i]) || break
x[i] isa Null || break
s = new_s
end
s
Expand Down Expand Up @@ -277,8 +277,9 @@ Base.done(itr::EachFailNull, state) = done(itr.x, state)
Base.eltype(itr::EachFailNull) = Nulls.T(eltype(itr.x))
@inline function Base.next(itr::EachFailNull, state)
v, s = next(itr.x, state)
# NOTE: v isa Null currently gives incorrect code, cf. JuliaLang/julia#24177
isnull(v) && throw(NullException())
(v::eltype(itr), s)
(v, s)
end

"""
Expand Down

0 comments on commit 921d956

Please sign in to comment.