From c84311ffe08d12c96d38b6464b2f0ba8cd567e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 12 Feb 2013 10:54:03 +0100 Subject: 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. --- lib/stdlib/src/filelib.erl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/stdlib/src') 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); -- cgit v1.2.3