Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit c84311ffe08d12c96d38b6464b2f0ba8cd567e42 1 parent 3c40105
Björn Gustavsson bjorng authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/stdlib/src/filelib.erl
12 lib/stdlib/src/filelib.erl
View
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.