Skip to content

Commit

Permalink
Prepare for invalidation-resistant calls to match
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Mar 8, 2022
1 parent f129b2b commit 6a7fd25
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions base/strings/substring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ convert(::Type{SubString{S}}, s::AbstractString) where {S<:AbstractString} =
SubString(convert(S, s))
convert(::Type{T}, s::T) where {T<:SubString} = s

# Regex match allows only Union{String, SubString{String}} so define conversion to this type
convert(::Type{Union{String, SubString{String}}}, s::String) = s
convert(::Type{Union{String, SubString{String}}}, s::SubString{String}) = s
convert(::Type{Union{String, SubString{String}}}, s::AbstractString) = convert(String, s)

function String(s::SubString{String})
parent = s.string
copy = GC.@preserve parent unsafe_string(pointer(parent, s.offset+1), s.ncodeunits)
Expand Down

0 comments on commit 6a7fd25

Please sign in to comment.