From 18b9fc2e6511db758e2b78f981e73565c6272642 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 16 Oct 2018 10:50:59 -0400 Subject: [PATCH] propgate inbounds to substring and use it in split (#29557) * propgate inbounds to substring and use it in split * remove Base prefix --- base/strings/substring.jl | 8 ++++---- base/strings/util.jl | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/base/strings/substring.jl b/base/strings/substring.jl index 1d14d943575b4..b18d63c9e1388 100644 --- a/base/strings/substring.jl +++ b/base/strings/substring.jl @@ -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 diff --git a/base/strings/util.jl b/base/strings/util.jl index 404c45cb6a1df..40b4fdebc6354 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -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 @@ -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