diff options
author | José Valim <[email protected]> | 2018-12-13 14:21:16 +0100 |
---|---|---|
committer | José Valim <[email protected]> | 2019-01-09 17:35:18 +0100 |
commit | faf6b3809544f40043b82552742572b6fa9bb339 (patch) | |
tree | 4b7b18fb8508fedc2ca6ac31b1424bf9293d19d4 /erts/emulator/beam/erl_bits.c | |
parent | 71215060abff81b61844f8517bde72a2252cef53 (diff) | |
download | otp-faf6b3809544f40043b82552742572b6fa9bb339.tar.gz otp-faf6b3809544f40043b82552742572b6fa9bb339.tar.bz2 otp-faf6b3809544f40043b82552742572b6fa9bb339.zip |
Do not allocate new bitstring/binary on empty append
Diffstat (limited to 'erts/emulator/beam/erl_bits.c')
-rw-r--r-- | erts/emulator/beam/erl_bits.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/erts/emulator/beam/erl_bits.c b/erts/emulator/beam/erl_bits.c index e82c776e70..051feb5977 100644 --- a/erts/emulator/beam/erl_bits.c +++ b/erts/emulator/beam/erl_bits.c @@ -1331,6 +1331,10 @@ erts_bs_append(Process* c_p, Eterm* reg, Uint live, Eterm build_size_term, } } + if (build_size_in_bits == 0) { + goto return_bin; + } + if((ERTS_UINT_MAX - build_size_in_bits) < erts_bin_offset) { c_p->freason = SYSTEM_LIMIT; return THE_NON_VALUE; @@ -1389,16 +1393,6 @@ erts_bs_append(Process* c_p, Eterm* reg, Uint live, Eterm build_size_term, Eterm* hp; /* - * Allocate heap space. - */ - heap_need = PROC_BIN_SIZE + ERL_SUB_BIN_SIZE + extra_words; - if (c_p->stop - c_p->htop < heap_need) { - (void) erts_garbage_collect(c_p, heap_need, reg, live+1); - bin = reg[live]; - } - hp = c_p->htop; - - /* * Calculate sizes. The size of the new binary, is the sum of the * build size and the size of the old binary. Allow some room * for growing. @@ -1412,6 +1406,19 @@ erts_bs_append(Process* c_p, Eterm* reg, Uint live, Eterm build_size_term, } } + if (build_size_in_bits == 0) { + goto return_bin; + } + + /* + * Allocate heap space. + */ + heap_need = PROC_BIN_SIZE + ERL_SUB_BIN_SIZE + extra_words; + if (c_p->stop - c_p->htop < heap_need) { + (void) erts_garbage_collect(c_p, heap_need, reg, live+1); + } + hp = c_p->htop; + if((ERTS_UINT_MAX - build_size_in_bits) < erts_bin_offset) { c_p->freason = SYSTEM_LIMIT; return THE_NON_VALUE; @@ -1471,6 +1478,16 @@ erts_bs_append(Process* c_p, Eterm* reg, Uint live, Eterm build_size_term, return make_binary(sb); } + + return_bin: + { + if (c_p->stop - c_p->htop < extra_words) { + reg[live] = bin; + (void) erts_garbage_collect(c_p, extra_words, reg, live+1); + bin = reg[live]; + } + return bin; + } } Eterm |