diff options
author | Kim Alvefur <zash@zash.se> | 2020-10-11 23:04:13 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-10-11 23:04:13 +0200 |
commit | 5b33f834fa2159a74cf0f80922f67b5e1f18a4d7 (patch) | |
tree | d9debc81153eb3764a6a4426b43f3a47b18d91d7 /util/paths.lua | |
parent | c812a980682ce678045ee8031b8b0da9237458f0 (diff) | |
download | prosody-5b33f834fa2159a74cf0f80922f67b5e1f18a4d7.tar.gz prosody-5b33f834fa2159a74cf0f80922f67b5e1f18a4d7.zip |
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.
Diffstat (limited to 'util/paths.lua')
-rw-r--r-- | util/paths.lua | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/util/paths.lua b/util/paths.lua index 036f315a..b75c35e5 100644 --- a/util/paths.lua +++ b/util/paths.lua @@ -37,8 +37,18 @@ function path_util.glob_to_pattern(glob) 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) |