Module talk:String: Difference between revisions

Content deleted Content added
top: fix gap above archives banner
Line 127:
{{edit fully-protected|Module:String|answered=yes}}
Please, add '''r''' to the word '''fist''' (resulting in ''fi'''r'''st''), line number 61. [[User:Gkiyoshinishimoto|Nishimoto, Gilberto Kiyoshi]] ([[User talk:Gkiyoshinishimoto|talk]]) 18:11, 25 October 2023 (UTC)
 
== Protected edit request on 3 September 2024 ==
 
{{edit fully-protected|Module:String}}
 
All of the Lua pseudo-regex special characters are in the ASCII range. See [[:en:UTF-8#Encoding]]. Therefore, we don't need at all to use the (costly) <code>mw.ustring.*</code> functions in some parts I have reviewed.
 
My request is to replace:
<syntaxhighlight lang="lua">
function str._escapePattern( pattern_str )
return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )
end
</syntaxhighlight>
 
with:
<syntaxhighlight lang="lua">
function str._escapePattern( pattern_str )
return string.gsub( pattern_str, "[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%0" )
end
</syntaxhighlight>
 
(I am also removing the capture group, which is unneeded as we can use the "%0" whole capture)
 
Second change: line 409, we can similarly replace:
<syntaxhighlight lang="lua">
replace = mw.ustring.gsub( replace, "%%", "%%%%" ) --Only need to escape replacement sequences.
</syntaxhighlight>
 
with:
<syntaxhighlight lang="lua">
replace = string.gsub( replace, "%%", "%%%%" ) --Only need to escape replacement sequences.
</syntaxhighlight>
 
These changes would significantly decrease the overhead of having the "plain mode" enabled in this module's functions.
 
[[User:Od1n|Od1n]] ([[User talk:Od1n|talk]]) 03:26, 3 September 2024 (UTC)