mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-09-24 10:49:52 +00:00
Only use mw.ustring when necessary
mw.ustring is really really slow. I've discovered that in a lot of modules on enwiki, upwards of 2/3 of the total runtime gets used when mw.html calls mw.ustring.gsub. This change checks whether any Unicode characters are present, and if not, calls string.gsub instead. Change-Id: Ia50061584be3901ae7428354c449236225c318db
This commit is contained in:
parent
08a39470c0
commit
f4501ccd22
|
@ -96,11 +96,14 @@ local function htmlEncode( s )
|
|||
end
|
||||
|
||||
local function cssEncode( s )
|
||||
-- XXX: I'm not sure this character set is complete.
|
||||
-- bug #68011: allow delete character (\127)
|
||||
return mw.ustring.gsub( s, '[^\32-\57\60-\127]', function ( m )
|
||||
return string.format( '\\%X ', mw.ustring.codepoint( m ) )
|
||||
end )
|
||||
-- mw.ustring is so slow that it's worth searching the whole string
|
||||
-- for non-ASCII characters to avoid it if possible
|
||||
return ( string.find( s, '[^%z\1-\127]' ) and mw.ustring or string )
|
||||
-- XXX: I'm not sure this character set is complete.
|
||||
-- bug #68011: allow delete character (\127)
|
||||
.gsub( s, '[^\32-\57\60-\127]', function ( m )
|
||||
return string.format( '\\%X ', mw.ustring.codepoint( m ) )
|
||||
end )
|
||||
end
|
||||
|
||||
-- Create a builder object. This is a separate function so that we can show the
|
||||
|
|
Loading…
Reference in a new issue