mirror of
https://github.com/bjc/prosody.git
synced 2025-04-01 20:27:39 +03:00
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.
This commit is contained in:
parent
c812a98068
commit
5b33f834fa
1 changed files with 12 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue