Skip to content

Commit

Permalink
Fix ambiguity error
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobnissen committed Oct 8, 2024
1 parent bab27c0 commit affaaf0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,36 @@ function Base.copyto!(dst::MutableMemoryView{T}, src::MemoryView{T}) where {T}
unsafe_copyto!(dst, src)
end

# The following two methods could be collapsed, but they aren't for two reasons:
# * To prevent ambiguity with Base
# * Because we DON'T want this code to run with MemoryView{Union{UInt8, Int8}}.
# The latter might not be an issue since I don't think it's possible to construct
# a Fix2 with a non-concrete type, but I'm not sure.
function Base.findnext(
p::Base.Fix2{<:Union{typeof(==), typeof(isequal)}, T},
p::Base.Fix2{<:Union{typeof(==), typeof(isequal)}, UInt8},
mem::MemoryView{UInt8},
start::Integer,
)
_findnext(mem, p.x, start)
end

function Base.findnext(
p::Base.Fix2{<:Union{typeof(==), typeof(isequal)}, Int8},
mem::MemoryView{Int8},
start::Integer,
)
_findnext(mem, p.x, start)
end

@inline function _findnext(
mem::MemoryView{T},
byte::Union{T},
start::Integer,
) where {T <: Union{UInt8, Int8}}
start = Int(start)::Int
real_start = max(start, 1)
v = @inbounds ImmutableMemoryView(mem[real_start:end])
v_ind = @something memchr(v, p.x) return nothing
v_ind = @something memchr(v, byte) return nothing
v_ind + real_start - 1
end

Expand Down

0 comments on commit affaaf0

Please sign in to comment.