From ec2b785a09959b7c0a85ac8e9ad9b36e7b2166a3 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Sun, 24 Sep 2017 12:46:28 +0200 Subject: base64:decode(List) put the List parameter first for improved performance --- lib/stdlib/src/base64.erl | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/stdlib/src/base64.erl b/lib/stdlib/src/base64.erl index 0eea2c0f1a..6e96f7d1f7 100644 --- a/lib/stdlib/src/base64.erl +++ b/lib/stdlib/src/base64.erl @@ -115,7 +115,7 @@ encode_binary(Bin) -> decode(Bin) when is_binary(Bin) -> decode_binary(<<>>, Bin); decode(List) when is_list(List) -> - decode_list(<<>>, List). + decode_list(List, <<>>). -spec mime_decode(Base64) -> Data when Base64 :: ascii_string() | ascii_binary(), @@ -262,39 +262,39 @@ mime_decode_binary_after_eq(Result0, <<>>, Eq) -> Result end. -decode_list(A, [C1 | Cs]) -> +decode_list([C1 | Cs], A) -> case element(C1, ?DECODE_MAP) of - ws -> decode_list(A, Cs); - B1 -> decode_list(A, B1, Cs) + ws -> decode_list(Cs, A); + B1 -> decode_list(Cs, A, B1) end; -decode_list(A, []) -> +decode_list([], A) -> A. -decode_list(A, B1, [C2 | Cs]) -> +decode_list([C2 | Cs], A, B1) -> case element(C2, ?DECODE_MAP) of - ws -> decode_list(A, B1, Cs); - B2 -> decode_list(A, B1, B2, Cs) + ws -> decode_list(Cs, A, B1); + B2 -> decode_list(Cs, A, B1, B2) end. -decode_list(A, B1, B2, [C3 | Cs]) -> +decode_list([C3 | Cs], A, B1, B2) -> case element(C3, ?DECODE_MAP) of - ws -> decode_list(A, B1, B2, Cs); - B3 -> decode_list(A, B1, B2, B3, Cs) + ws -> decode_list(Cs, A, B1, B2); + B3 -> decode_list(Cs, A, B1, B2, B3) end. -decode_list(A, B1, B2, B3, [C4 | Cs]) -> +decode_list([C4 | Cs], A, B1, B2, B3) -> case element(C4, ?DECODE_MAP) of - ws -> decode_list(A, B1, B2, B3, Cs); - eq when B3 =:= eq -> only_ws(<>, Cs); - eq -> only_ws(<>, Cs); - B4 -> decode_list(<>, Cs) + ws -> decode_list(Cs, A, B1, B2, B3); + eq when B3 =:= eq -> only_ws(Cs, <>); + eq -> only_ws(Cs, <>); + B4 -> decode_list(Cs, <>) end. -only_ws(A, []) -> +only_ws([], A) -> A; -only_ws(A, [C | Cs]) -> +only_ws([C | Cs], A) -> case element(C, ?DECODE_MAP) of - ws -> only_ws(A, Cs); + ws -> only_ws(Cs, A); _ -> erlang:error(function_clause) end. -- cgit v1.2.3