Changeset

11183:2ac63715ef6f

util.paths: Optimize path joining with few arguments A casual search suggests that the majority of paths.join() calls involve only two arguments. This saves the creation of a table for up to 3 arguments. Looks like 3x faster for 3 arguments or less, 5% slower when it uses the array to concatenate.
author Kim Alvefur <zash@zash.se>
date Sun, 11 Oct 2020 23:04:13 +0200
parents 11182:bab8d01e139a
children 11184:2ede7f43ccfe
files util/paths.lua
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/util/paths.lua	Sat Oct 17 19:24:44 2020 +0200
+++ b/util/paths.lua	Sun Oct 11 23:04:13 2020 +0200
@@ -37,8 +37,18 @@
 	end).."$";
 end
 
-function path_util.join(...)
-	return t_concat({...}, path_sep);
+function path_util.join(a, b, c, ...) -- (... : string) --> string
+	-- Optimization: Avoid creating table for most uses
+	if b then
+		if c then
+			if ... then
+				return t_concat({a,b,c,...}, path_sep);
+			end
+			return a..path_sep..b..path_sep..c;
+		end
+		return a..path_sep..b;
+	end
+	return a;
 end
 
 function path_util.complement_lua_path(installer_plugin_path)