diff options
author | Björn Gustavsson <[email protected]> | 2011-11-08 11:06:21 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-11-08 11:06:21 +0100 |
commit | 4a67884525973f104e9b05ea80bc16ffc71fada8 (patch) | |
tree | 00ef8d308f061737d0b1c8a7cf65598737cd8246 /lib | |
parent | 766a0a84f0b9e4b9341fb06364bf5430574588a6 (diff) | |
parent | 3d5cdb216fa5652bd8552ef4fa4eee310e543b42 (diff) | |
download | otp-4a67884525973f104e9b05ea80bc16ffc71fada8.tar.gz otp-4a67884525973f104e9b05ea80bc16ffc71fada8.tar.bz2 otp-4a67884525973f104e9b05ea80bc16ffc71fada8.zip |
Merge branch 'bjorn/create-less-garbage'
* bjorn/create-less-garbage:
Optimize filename:basename/1 to produce less garbage
Optimize filename:extension/1 to produce less garbage
sys.c for Unix: Undo caching of utsname in os_flavor()
Pre-build the tuples returned by os:type/0 and os:version/0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/stdlib/src/filename.erl | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/stdlib/src/filename.erl b/lib/stdlib/src/filename.erl index 1cb9e4a25e..2fc9128e4e 100644 --- a/lib/stdlib/src/filename.erl +++ b/lib/stdlib/src/filename.erl @@ -147,9 +147,10 @@ basename(Name) when is_binary(Name) -> end; basename(Name0) -> - Name = flatten(Name0), + Name1 = flatten(Name0), {DirSep2, DrvSep} = separators(), - basename1(skip_prefix(Name, DrvSep), [], DirSep2). + Name = skip_prefix(Name1, DrvSep), + basename1(Name, Name, DirSep2). win_basenameb(<<Letter,$:,Rest/binary>>) when ?IS_DRIVELETTER(Letter) -> basenameb(Rest,[<<"/">>,<<"\\">>]); @@ -167,16 +168,18 @@ basenameb(Bin,Sep) -> -basename1([$/|[]], Tail, DirSep2) -> - basename1([], Tail, DirSep2); +basename1([$/], Tail0, _DirSep2) -> + %% End of filename -- must get rid of trailing directory separator. + [_|Tail] = lists:reverse(Tail0), + lists:reverse(Tail); basename1([$/|Rest], _Tail, DirSep2) -> - basename1(Rest, [], DirSep2); + basename1(Rest, Rest, DirSep2); basename1([DirSep2|Rest], Tail, DirSep2) when is_integer(DirSep2) -> basename1([$/|Rest], Tail, DirSep2); basename1([Char|Rest], Tail, DirSep2) when is_integer(Char) -> - basename1(Rest, [Char|Tail], DirSep2); + basename1(Rest, Tail, DirSep2); basename1([], Tail, _DirSep2) -> - lists:reverse(Tail). + Tail. skip_prefix(Name, false) -> Name; @@ -369,8 +372,8 @@ extension(Name0) -> Name = flatten(Name0), extension(Name, [], major_os_type()). -extension([$.|Rest], _Result, OsType) -> - extension(Rest, [$.], OsType); +extension([$.|Rest]=Result, _Result, OsType) -> + extension(Rest, Result, OsType); extension([Char|Rest], [], OsType) when is_integer(Char) -> extension(Rest, [], OsType); extension([$/|Rest], _Result, OsType) -> @@ -378,9 +381,9 @@ extension([$/|Rest], _Result, OsType) -> extension([$\\|Rest], _Result, win32) -> extension(Rest, [], win32); extension([Char|Rest], Result, OsType) when is_integer(Char) -> - extension(Rest, [Char|Result], OsType); + extension(Rest, Result, OsType); extension([], Result, _OsType) -> - lists:reverse(Result). + Result. %% Joins a list of filenames with directory separators. |