diff options
author | Björn Gustavsson <[email protected]> | 2017-02-27 12:22:56 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2017-02-27 12:22:56 +0100 |
commit | 751c2b4fd2b121076f0b97de1b4ccac8284d6ef2 (patch) | |
tree | b898f45953c98c2db1a1c23fb752ac4d22b1e16e | |
parent | 3202e753383d495bce8008721e94428788d4f400 (diff) | |
parent | bee8f839296e0424ddaf3a235ca285c2525cd28e (diff) | |
download | otp-751c2b4fd2b121076f0b97de1b4ccac8284d6ef2.tar.gz otp-751c2b4fd2b121076f0b97de1b4ccac8284d6ef2.tar.bz2 otp-751c2b4fd2b121076f0b97de1b4ccac8284d6ef2.zip |
Merge branch 'bjorn/compiler/opt-binary-strings/OTP-14125'
* bjorn/compiler/opt-binary-strings/OTP-14125:
v3_core: Combine binary strings to larger integers
-rw-r--r-- | lib/compiler/src/v3_core.erl | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl index 14cd41ae27..8dea7ec03a 100644 --- a/lib/compiler/src/v3_core.erl +++ b/lib/compiler/src/v3_core.erl @@ -1059,13 +1059,30 @@ count_bits(Int) -> count_bits_1(0, Bits) -> Bits; count_bits_1(Int, Bits) -> count_bits_1(Int bsr 64, Bits+64). -bin_expand_strings(Es) -> - foldr(fun ({bin_element,Line,{string,_,S},Sz,Ts}, Es1) -> - foldr(fun (C, Es2) -> - [{bin_element,Line,{char,Line,C},Sz,Ts}|Es2] - end, Es1, S); - (E, Es1) -> [E|Es1] - end, [], Es). +bin_expand_strings(Es0) -> + foldr(fun ({bin_element,Line,{string,_,S},{integer,_,8},_}, Es) -> + bin_expand_string(S, Line, 0, 0) ++ Es; + ({bin_element,Line,{string,_,S},Sz,Ts}, Es1) -> + foldr( + fun (C, Es) -> + [{bin_element,Line,{char,Line,C},Sz,Ts}|Es] + end, Es1, S); + (E, Es) -> + [E|Es] + end, [], Es0). + +bin_expand_string(S, Line, Val, Size) when Size >= 2048 -> + Combined = make_combined(Line, Val, Size), + [Combined|bin_expand_string(S, Line, 0, 0)]; +bin_expand_string([H|T], Line, Val, Size) -> + bin_expand_string(T, Line, (Val bsl 8) bor H, Size+8); +bin_expand_string([], Line, Val, Size) -> + [make_combined(Line, Val, Size)]. + +make_combined(Line, Val, Size) -> + {bin_element,Line,{integer,Line,Val}, + {integer,Line,Size}, + [integer,{unit,1},unsigned,big]}. expr_bin_1(Es, St) -> foldr(fun (E, {Ces,Esp,St0}) -> |