From dd57992f5e34c7a7bdecca84ce1f726b0c846299 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Sun, 7 Jul 2024 19:40:16 +0100 Subject: [PATCH] De-reference Type/Bucket/Key (#38) * De-reference Type/Bucket/Key Maybe otherwise small binaries which hold a reference count to a much larger binary * Only copy if > 64 bytes Has already been copied to the local heap otherwise --- src/riak_object.erl | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/riak_object.erl b/src/riak_object.erl index 6b04dcfcd..e32c84899 100644 --- a/src/riak_object.erl +++ b/src/riak_object.erl @@ -1237,16 +1237,35 @@ nextgenrepl_binarykey(B, K) -> %% @doc Deocde for nextgenrepl -spec nextgenrepl_decode(binary()) -> riak_object()|repl_ref(). -nextgenrepl_decode(<<1:4/integer, C:1/integer, R:1/integer, _:2/integer, - 0:32/integer, BL:32/integer, B:BL/binary, - KL:32/integer, K:KL/binary, - ObjBin/binary>>) -> - nextgenrepl_decode(B, K, C == 1, R == 1, ObjBin); -nextgenrepl_decode(<<1:4/integer, C:1/integer, R:1/integer, _:2/integer, - TL:32/integer, T:TL/binary, BL:32/integer, B:BL/binary, - KL:32/integer, K:KL/binary, - ObjBin/binary>>) -> - nextgenrepl_decode({T, B}, K, C == 1, R == 1, ObjBin). +nextgenrepl_decode( + <<1:4/integer, C:1/integer, R:1/integer, _:2/integer, + 0:32/integer, + BL:32/integer, B:BL/binary, KL:32/integer, K:KL/binary, + ObjBin/binary>>) -> + nextgenrepl_decode( + maybe_copy(B, BL), + maybe_copy(K, KL), + C == 1, + R == 1, + ObjBin + ); +nextgenrepl_decode( + <<1:4/integer, C:1/integer, R:1/integer, _:2/integer, + TL:32/integer, T:TL/binary, + BL:32/integer, B:BL/binary, KL:32/integer, K:KL/binary, + ObjBin/binary>>) -> + nextgenrepl_decode( + {maybe_copy(T, TL), maybe_copy(B, BL)}, + maybe_copy(K, KL), + C == 1, + R == 1, + ObjBin + ). + +maybe_copy(B, BL) when BL > 64 -> + binary:copy(B); +maybe_copy(B, _BL) -> + B. nextgenrepl_decode(B, K, _, true, MetaBin) -> <> =