Comparison

util/format.lua @ 12040:337b489532b7

util.format: Optimize most common integer format A search for log formats in use points to %s being the most common, followed by %d, so worth having a fast path for that. %g works well with most numbers and is what Lua 5.1 and 5.2 used
author Kim Alvefur <zash@zash.se>
date Mon, 13 Dec 2021 16:38:33 +0100
parent 12039:e0a8c5b1ab4f
child 12220:25b853e64d83
comparison
equal deleted inserted replaced
12039:e0a8c5b1ab4f 12040:337b489532b7
67 local t = type(arg); 67 local t = type(arg);
68 68
69 if option == "s" and t == "string" and not arg:find("[%z\1-\31\128-\255]") then 69 if option == "s" and t == "string" and not arg:find("[%z\1-\31\128-\255]") then
70 -- No UTF-8 or control characters, assumed to be the common case. 70 -- No UTF-8 or control characters, assumed to be the common case.
71 return 71 return
72 elseif t == "number" then
73 if option == "g" or (option == "d" and num_type(arg) == "integer") then return end
72 elseif option == "s" and t ~= "string" then 74 elseif option == "s" and t ~= "string" then
73 arg = tostring(arg); 75 arg = tostring(arg);
74 t = "string"; 76 t = "string";
75 end 77 end
76 78