From f3756139b99a77a29dd7325d0b2d706eed8a881f Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Tue, 7 Nov 2017 17:38:39 +0100 Subject: stdlib: Minor optimization of base64 Using /bits instead of /binary is faster when constructing binaries. --- lib/stdlib/src/base64.erl | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'lib/stdlib/src/base64.erl') diff --git a/lib/stdlib/src/base64.erl b/lib/stdlib/src/base64.erl index 6ff6020e53..b4ff7b037f 100644 --- a/lib/stdlib/src/base64.erl +++ b/lib/stdlib/src/base64.erl @@ -66,15 +66,15 @@ encode_list_to_string([B1,B2,B3|Ls]) -> encode_binary(<<>>, A) -> A; encode_binary(<>, A) -> - <>; + <>; encode_binary(<>, A) -> - <>; encode_binary(<>, A) -> BB = (B1 bsl 16) bor (B2 bsl 8) bor B3, encode_binary(Ls, - <>). @@ -82,15 +82,15 @@ encode_binary(<>, A) -> encode_list([], A) -> A; encode_list([B1], A) -> - <>; + <>; encode_list([B1,B2], A) -> - <>; encode_list([B1,B2,B3|Ls], A) -> BB = (B1 bsl 16) bor (B2 bsl 8) bor B3, encode_list(Ls, - <>). @@ -195,9 +195,9 @@ mime_decode_list_after_eq([C | Cs], A, B1, B2, B3) -> _ -> mime_decode_list_after_eq(Cs, A, B1, B2, B3) end; mime_decode_list_after_eq([], A, B1, B2, eq) -> - <>; + <>; mime_decode_list_after_eq([], A, B1, B2, B3) -> - <>. + <>. mime_decode_binary(<<0:8, Cs/bits>>, A) -> mime_decode_binary(Cs, A); @@ -253,9 +253,9 @@ mime_decode_binary_after_eq(<>, A, B1, B2, B3) -> _ -> mime_decode_binary_after_eq(Cs, A, B1, B2, B3) end; mime_decode_binary_after_eq(<<>>, A, B1, B2, eq) -> - <>; + <>; mime_decode_binary_after_eq(<<>>, A, B1, B2, B3) -> - <>. + <>. mime_decode_list_to_string([0 | Cs]) -> mime_decode_list_to_string(Cs); @@ -346,9 +346,9 @@ decode_list([C3 | Cs], A, B1, B2) -> decode_list([C4 | Cs], A, B1, B2, B3) -> case b64d(C4) of ws -> decode_list(Cs, A, B1, B2, B3); - eq when B3 =:= eq -> only_ws(Cs, <>); - eq -> only_ws(Cs, <>); - B4 -> decode_list(Cs, <>) + eq when B3 =:= eq -> only_ws(Cs, <>); + eq -> only_ws(Cs, <>); + B4 -> decode_list(Cs, <>) end. decode_binary(<>, A) -> @@ -374,9 +374,9 @@ decode_binary(<>, A, B1, B2) -> decode_binary(<>, A, B1, B2, B3) -> case b64d(C4) of ws -> decode_binary(Cs, A, B1, B2, B3); - eq when B3 =:= eq -> only_ws_binary(Cs, <>); - eq -> only_ws_binary(Cs, <>); - B4 -> decode_binary(Cs, <>) + eq when B3 =:= eq -> only_ws_binary(Cs, <>); + eq -> only_ws_binary(Cs, <>); + B4 -> decode_binary(Cs, <>) end. only_ws_binary(<<>>, A) -> -- cgit v1.2.3