aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-02-12 10:54:03 +0100
committerBjörn Gustavsson <[email protected]>2013-02-13 11:58:45 +0100
commitc84311ffe08d12c96d38b6464b2f0ba8cd567e42 (patch)
tree8970b8a50f0bee046bc8c96166c16dbddb0a177a /lib/stdlib/src
parent3c40105f4666e1c38752a5bbf1c282c221dda967 (diff)
downloadotp-c84311ffe08d12c96d38b6464b2f0ba8cd567e42.tar.gz
otp-c84311ffe08d12c96d38b6464b2f0ba8cd567e42.tar.bz2
otp-c84311ffe08d12c96d38b6464b2f0ba8cd567e42.zip
Replace filename:join/2 with '++'
Under controlled circumstances (and we are in control of the circumstances), filename:join/2 can be replaced with '++'. '++' is faster because it is implmented in C, does not need to look at the list elements it copies, and does not need to copy its right operand.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/filelib.erl12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/stdlib/src/filelib.erl b/lib/stdlib/src/filelib.erl
index b1a5b7a8a9..8a32220a7b 100644
--- a/lib/stdlib/src/filelib.erl
+++ b/lib/stdlib/src/filelib.erl
@@ -275,9 +275,10 @@ do_wildcard_2([], _, Result, _Mod) ->
do_wildcard_3(Base, [[double_star]|Rest], Result, Mod) ->
lists:sort(do_double_star(".", [Base], Rest, Result, Mod, true));
-do_wildcard_3(Base, [Pattern|Rest], Result, Mod) ->
- case do_list_dir(Base, Mod) of
+do_wildcard_3(Base0, [Pattern|Rest], Result, Mod) ->
+ case do_list_dir(Base0, Mod) of
{ok, Files0} ->
+ Base = prepare_base(Base0),
Files = lists:sort(Files0),
Matches = wildcard_4(Pattern, Files, Base, []),
do_wildcard_2(Matches, Rest, Result, Mod);
@@ -290,7 +291,7 @@ do_wildcard_3(Base, [], Result, _Mod) ->
wildcard_4(Pattern, [File|Rest], Base, Result) ->
case wildcard_5(Pattern, File) of
true ->
- wildcard_4(Pattern, Rest, Base, [filename:join(Base, File)|Result]);
+ wildcard_4(Pattern, Rest, Base, [Base++File|Result]);
false ->
wildcard_4(Pattern, Rest, Base, Result)
end;
@@ -323,6 +324,11 @@ wildcard_5([], [_|_]) ->
wildcard_5([_|_], []) ->
false.
+prepare_base(Base0) ->
+ Base1 = filename:join(Base0, "x"),
+ "x"++Base2 = lists:reverse(Base1),
+ lists:reverse(Base2).
+
do_double_star(Base, [H|T], Rest, Result, Mod, Root) ->
Full = case Root of
false -> filename:join(Base, H);