aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-13 16:38:33 +0100
committerKim Alvefur <zash@zash.se>2021-12-13 16:38:33 +0100
commit0e997ab3f9673383aa32310f71b87a91e92881f2 (patch)
tree5d7e60b7d3dd29fc8d1f9e064447ce9a344cf1c5
parent58c91153514c6e07ba3bed20473a92d87ddd3ca5 (diff)
downloadprosody-0e997ab3f9673383aa32310f71b87a91e92881f2.tar.gz
prosody-0e997ab3f9673383aa32310f71b87a91e92881f2.zip
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
-rw-r--r--util/format.lua2
1 files changed, 2 insertions, 0 deletions
diff --git a/util/format.lua b/util/format.lua
index e93c9096..1cd8d81b 100644
--- a/util/format.lua
+++ b/util/format.lua
@@ -69,6 +69,8 @@ local function format(formatstring, ...)
if option == "s" and t == "string" and not arg:find("[%z\1-\31\128-\255]") then
-- No UTF-8 or control characters, assumed to be the common case.
return
+ elseif t == "number" then
+ if option == "g" or (option == "d" and num_type(arg) == "integer") then return end
elseif option == "s" and t ~= "string" then
arg = tostring(arg);
t = "string";