Skip to content

Commit

Permalink
unicode: specialize utf8proc_map sufficiently (JuliaLang#54385)
Browse files Browse the repository at this point in the history
This specialization is more consistent with the callees of this
function, which are specialized on the type / identity of this transform
function.

This cleans up an unnecessary dynamic dispatch in this code.

Co-authored-by: gbaraldi <[email protected]>
  • Loading branch information
topolarity and gbaraldi authored May 7, 2024
1 parent d2399e6 commit a267cec
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions base/strings/unicode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ function utf8proc_decompose(str, options, buffer, nwords, chartransform::typeof(
ret < 0 && utf8proc_error(ret)
return ret
end
function utf8proc_decompose(str, options, buffer, nwords, chartransform::T) where T
ret = ccall(:utf8proc_decompose_custom, Int, (Ptr{UInt8}, Int, Ptr{UInt8}, Int, Cint, Ptr{Cvoid}, Ref{T}),
function utf8proc_decompose(str, options, buffer, nwords, chartransform::F) where F
ret = ccall(:utf8proc_decompose_custom, Int, (Ptr{UInt8}, Int, Ptr{UInt8}, Int, Cint, Ptr{Cvoid}, Ref{F}),
str, sizeof(str), buffer, nwords, options,
@cfunction(utf8proc_custom_func, UInt32, (UInt32, Ref{T})), chartransform)
@cfunction(utf8proc_custom_func, UInt32, (UInt32, Ref{F})), chartransform)
ret < 0 && utf8proc_error(ret)
return ret
end

function utf8proc_map(str::Union{String,SubString{String}}, options::Integer, chartransform=identity)
function utf8proc_map(str::Union{String,SubString{String}}, options::Integer, chartransform::F = identity) where F
nwords = utf8proc_decompose(str, options, C_NULL, 0, chartransform)
buffer = Base.StringVector(nwords*4)
nwords = utf8proc_decompose(str, options, buffer, nwords, chartransform)
Expand All @@ -184,7 +184,7 @@ const _julia_charmap = Dict{UInt32,UInt32}(
0x210F => 0x0127,
)

utf8proc_map(s::AbstractString, flags::Integer, chartransform=identity) = utf8proc_map(String(s), flags, chartransform)
utf8proc_map(s::AbstractString, flags::Integer, chartransform::F = identity) where F = utf8proc_map(String(s), flags, chartransform)

# Documented in Unicode module
function normalize(
Expand Down

0 comments on commit a267cec

Please sign in to comment.