Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propgate inbounds to substring and use it in split #29557

Merged
merged 2 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Base.@propagate_inbounds Base.SubString(s::T, i::Int, j::Int) where {T<:AbstractString} = SubString{T}(s, i, j)
Base.@propagate_inbounds SubString(s::AbstractString, i::Integer, j::Integer=lastindex(s)) = SubString(s, Int(i), Int(j))
Base.@propagate_inbounds SubString(s::AbstractString, r::UnitRange{<:Integer}) = SubString(s, first(r), last(r))

function SubString(s::SubString, i::Int, j::Int)
Base.@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