diff options
author | Björn Gustavsson <[email protected]> | 2016-04-28 07:12:27 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-04-29 09:58:27 +0200 |
commit | 27098673c0654add1784852b54d4600a2775773e (patch) | |
tree | c3f030779cfb4f3bd31511b5be80c6b3f2e6f025 | |
parent | 620676577bb80a41a991b52254b445589330a3da (diff) | |
download | otp-27098673c0654add1784852b54d4600a2775773e.tar.gz otp-27098673c0654add1784852b54d4600a2775773e.tar.bz2 otp-27098673c0654add1784852b54d4600a2775773e.zip |
Simplify and speed up del_ebin/1
It is faster and easier to use filename:split/1 and filename:join/1
than use four different 'filename' operations. Each call in the
original call first flattens the input list, and then traverse the
entire string to the end. So there are roughly 8 complete traversals.
In comparison, filename:split/1 will traverse the input string
twice (once to flatten, once to split) and filename:join/1 once.
For background on why this optimization is worthwhile, here is the
result of profiling the start-up of the run-time system on my computer
(done before this optimization):
$ $ERL_TOP/bin/erl -profile_boot
.
.
.
filename:join1/4 - 13573 : 13805 us
erlang:finish_loading/1 - 27 : 19963 us
filename:do_flatten/2 - 29337 : 49518 us
erlang:prepare_loading/2 - 49 : 52270 us
Note that filename:do_flatten/2 ends up in second place, almost
as expensive as erlang:prepare_loading/2. Your mileage may vary,
depending on the length of $ERL_TOP and the number of extra
directories added to the path using $ERL_LIBS.
-rw-r--r-- | lib/kernel/src/code_server.erl | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl index 25dddb1f6c..02fc043325 100644 --- a/lib/kernel/src/code_server.erl +++ b/lib/kernel/src/code_server.erl @@ -927,22 +927,22 @@ check_pars(Name,Dir) -> end. del_ebin(Dir) -> - case filename:basename(Dir) of - "ebin" -> - Dir2 = filename:dirname(Dir), - Dir3 = filename:dirname(Dir2), - Ext = archive_extension(), - case filename:extension(Dir3) of - E when E =:= Ext -> - %% Strip archive extension - filename:join([filename:dirname(Dir3), - filename:basename(Dir3, Ext)]); - _ -> - Dir2 - end; - _ -> - Dir - end. + filename:join(del_ebin_1(filename:split(Dir))). + +del_ebin_1([Parent,App,"ebin"]) -> + Ext = archive_extension(), + case filename:basename(Parent, Ext) of + Parent -> + %% Plain directory. + [Parent,App]; + Archive -> + %% Archive. + [Archive] + end; +del_ebin_1([H|T]) -> + [H|del_ebin_1(T)]; +del_ebin_1([]) -> + []. replace_name(Dir, Db) -> case get_name(Dir) of |