Skip to content

Commit 41c2498

Browse files
committed
propgate inbounds to substring and use it in split (#29557)
* propgate inbounds to substring and use it in split * remove Base prefix (cherry picked from commit 18b9fc2)
1 parent f91ff61 commit 41c2498

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

base/strings/substring.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ struct SubString{T<:AbstractString} <: AbstractString
3535
end
3636
end
3737

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

42-
function SubString(s::SubString, i::Int, j::Int)
42+
@propagate_inbounds function SubString(s::SubString, i::Int, j::Int)
4343
@boundscheck i j && checkbounds(s, i:j)
4444
SubString(s.string, s.offset+i, s.offset+j)
4545
end

base/strings/util.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function _split(str::AbstractString, splitter, limit::Integer, keepempty::Bool,
323323
while 0 < j <= n && length(strs) != limit-1
324324
if i < k
325325
if keepempty || i < j
326-
push!(strs, SubString(str,i,prevind(str,j)))
326+
push!(strs, @inbounds SubString(str,i,prevind(str,j)))
327327
end
328328
i = k
329329
end
@@ -334,7 +334,7 @@ function _split(str::AbstractString, splitter, limit::Integer, keepempty::Bool,
334334
end
335335
end
336336
if keepempty || i <= ncodeunits(str)
337-
push!(strs, SubString(str,i))
337+
push!(strs, @inbounds SubString(str,i))
338338
end
339339
return strs
340340
end

0 commit comments

Comments
 (0)