Changeset

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
parents 12039:e0a8c5b1ab4f
children 12041:def20683c161
files util/format.lua
diffstat 1 files changed, 2 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util/format.lua	Mon Dec 13 16:34:55 2021 +0100
+++ b/util/format.lua	Mon Dec 13 16:38:33 2021 +0100
@@ -69,6 +69,8 @@
 		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";