Skip to content

Commit a267cec

Browse files
topolaritygbaraldi
andauthored
unicode: specialize utf8proc_map sufficiently (#54385)
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]>
1 parent d2399e6 commit a267cec

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

base/strings/unicode.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ function utf8proc_decompose(str, options, buffer, nwords, chartransform::typeof(
157157
ret < 0 && utf8proc_error(ret)
158158
return ret
159159
end
160-
function utf8proc_decompose(str, options, buffer, nwords, chartransform::T) where T
161-
ret = ccall(:utf8proc_decompose_custom, Int, (Ptr{UInt8}, Int, Ptr{UInt8}, Int, Cint, Ptr{Cvoid}, Ref{T}),
160+
function utf8proc_decompose(str, options, buffer, nwords, chartransform::F) where F
161+
ret = ccall(:utf8proc_decompose_custom, Int, (Ptr{UInt8}, Int, Ptr{UInt8}, Int, Cint, Ptr{Cvoid}, Ref{F}),
162162
str, sizeof(str), buffer, nwords, options,
163-
@cfunction(utf8proc_custom_func, UInt32, (UInt32, Ref{T})), chartransform)
163+
@cfunction(utf8proc_custom_func, UInt32, (UInt32, Ref{F})), chartransform)
164164
ret < 0 && utf8proc_error(ret)
165165
return ret
166166
end
167167

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

187-
utf8proc_map(s::AbstractString, flags::Integer, chartransform=identity) = utf8proc_map(String(s), flags, chartransform)
187+
utf8proc_map(s::AbstractString, flags::Integer, chartransform::F = identity) where F = utf8proc_map(String(s), flags, chartransform)
188188

189189
# Documented in Unicode module
190190
function normalize(

0 commit comments

Comments
 (0)