diff options
author | Björn Gustavsson <[email protected]> | 2013-02-12 11:13:04 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-02-13 11:58:45 +0100 |
commit | 3fafadfc76d061d5d2f30afde3e647f8b8282e37 (patch) | |
tree | 2dd8fd03a447f09d247d9f9b132541399f4939c0 | |
parent | c84311ffe08d12c96d38b6464b2f0ba8cd567e42 (diff) | |
download | otp-3fafadfc76d061d5d2f30afde3e647f8b8282e37.tar.gz otp-3fafadfc76d061d5d2f30afde3e647f8b8282e37.tar.bz2 otp-3fafadfc76d061d5d2f30afde3e647f8b8282e37.zip |
Only sort the result list once, just before returning
There does not seem to be any advantage of sorting the result of
file:list_dir/1 directly. Disadvantages are that we'll need to be
careful to keep the result sorted, and that we could waste time
sorting filenames that the pattern matching will discard anyway.
-rw-r--r-- | lib/stdlib/src/filelib.erl | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/stdlib/src/filelib.erl b/lib/stdlib/src/filelib.erl index 8a32220a7b..c936d08db4 100644 --- a/lib/stdlib/src/filelib.erl +++ b/lib/stdlib/src/filelib.erl @@ -252,13 +252,14 @@ ensure_dir(F) -> do_wildcard(Pattern, Cwd, Mod) -> {Compiled,PrefixLen} = compile_wildcard(Pattern, Cwd), - Files = do_wildcard_1(Compiled, Mod), - if - PrefixLen =:= 0 -> - Files; - true -> - [lists:nthtail(PrefixLen, File) || File <- Files] - end. + Files0 = do_wildcard_1(Compiled, Mod), + Files = if + PrefixLen =:= 0 -> + Files0; + true -> + [lists:nthtail(PrefixLen, File) || File <- Files0] + end, + lists:sort(Files). do_wildcard_1({exists,File}, Mod) -> case eval_read_file_info(File, Mod) of @@ -274,12 +275,11 @@ do_wildcard_2([], _, Result, _Mod) -> Result. do_wildcard_3(Base, [[double_star]|Rest], Result, Mod) -> - lists:sort(do_double_star(".", [Base], Rest, Result, Mod, true)); + do_double_star(".", [Base], Rest, Result, Mod, true); do_wildcard_3(Base0, [Pattern|Rest], Result, Mod) -> case do_list_dir(Base0, Mod) of - {ok, Files0} -> + {ok, Files} -> Base = prepare_base(Base0), - Files = lists:sort(Files0), Matches = wildcard_4(Pattern, Files, Base, []), do_wildcard_2(Matches, Rest, Result, Mod); _ -> |