Software /
code /
prosody
Comparison
util/paths.lua @ 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 |
parent | 10402:0971694b30a8 |
comparison
equal
deleted
inserted
replaced
11182:bab8d01e139a | 11183:2ac63715ef6f |
---|---|
35 return "%"..c; | 35 return "%"..c; |
36 end | 36 end |
37 end).."$"; | 37 end).."$"; |
38 end | 38 end |
39 | 39 |
40 function path_util.join(...) | 40 function path_util.join(a, b, c, ...) -- (... : string) --> string |
41 return t_concat({...}, path_sep); | 41 -- Optimization: Avoid creating table for most uses |
42 if b then | |
43 if c then | |
44 if ... then | |
45 return t_concat({a,b,c,...}, path_sep); | |
46 end | |
47 return a..path_sep..b..path_sep..c; | |
48 end | |
49 return a..path_sep..b; | |
50 end | |
51 return a; | |
42 end | 52 end |
43 | 53 |
44 function path_util.complement_lua_path(installer_plugin_path) | 54 function path_util.complement_lua_path(installer_plugin_path) |
45 -- Checking for duplicates | 55 -- Checking for duplicates |
46 -- The commands using luarocks need the path to the directory that has the /share and /lib folders. | 56 -- The commands using luarocks need the path to the directory that has the /share and /lib folders. |