Skip to content

Commit

Permalink
propgate inbounds to substring and use it in split (#29557)
Browse files Browse the repository at this point in the history
* propgate inbounds to substring and use it in split

* remove Base prefix

(cherry picked from commit 18b9fc2)
  • Loading branch information
KristofferC committed Nov 2, 2018
1 parent df5618b commit 13b3983
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions base/strings/substring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ struct SubString{T<:AbstractString} <: AbstractString
end
end

SubString(s::T, i::Int, j::Int) where {T<:AbstractString} = SubString{T}(s, i, j)
SubString(s::AbstractString, i::Integer, j::Integer=lastindex(s)) = SubString(s, Int(i), Int(j))
SubString(s::AbstractString, r::UnitRange{<:Integer}) = SubString(s, first(r), last(r))
@propagate_inbounds SubString(s::T, i::Int, j::Int) where {T<:AbstractString} = SubString{T}(s, i, j)
@propagate_inbounds SubString(s::AbstractString, i::Integer, j::Integer=lastindex(s)) = SubString(s, Int(i), Int(j))
@propagate_inbounds SubString(s::AbstractString, r::UnitRange{<:Integer}) = SubString(s, first(r), last(r))

function SubString(s::SubString, i::Int, j::Int)
@propagate_inbounds function SubString(s::SubString, i::Int, j::Int)
@boundscheck i j && checkbounds(s, i:j)
SubString(s.string, s.offset+i, s.offset+j)
end
Expand Down
4 changes: 2 additions & 2 deletions base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function _split(str::AbstractString, splitter, limit::Integer, keepempty::Bool,
while 0 < j <= n && length(strs) != limit-1
if i < k
if keepempty || i < j
push!(strs, SubString(str,i,prevind(str,j)))
push!(strs, @inbounds SubString(str,i,prevind(str,j)))
end
i = k
end
Expand All @@ -334,7 +334,7 @@ function _split(str::AbstractString, splitter, limit::Integer, keepempty::Bool,
end
end
if keepempty || i <= ncodeunits(str)
push!(strs, SubString(str,i))
push!(strs, @inbounds SubString(str,i))
end
return strs
end
Expand Down

0 comments on commit 13b3983

Please sign in to comment.