From f287895db0e48b720d6cac2ad2773116a375bd08 Mon Sep 17 00:00:00 2001 From: martinsumner Date: Fri, 17 Mar 2017 10:43:34 +0000 Subject: [PATCH] Pass out slots as a binary If we convetr firts to a list, then the list has to be copied - passing out as binaries means the bulk can be passed as references --- src/leveled_sst.erl | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/leveled_sst.erl b/src/leveled_sst.erl index 489715e..498e043 100644 --- a/src/leveled_sst.erl +++ b/src/leveled_sst.erl @@ -201,7 +201,12 @@ sst_getkvrange(Pid, StartKey, EndKey, ScanWidth) -> infinity). sst_getslots(Pid, SlotList) -> - gen_fsm:sync_send_event(Pid, {get_slots, SlotList}, infinity). + SlotBins = gen_fsm:sync_send_event(Pid, {get_slots, SlotList}, infinity), + FetchFun = + fun({SlotBin, SK, EK}, Acc) -> + Acc ++ binaryslot_trimmedlist(SlotBin, SK, EK) + end, + lists:foldl(FetchFun, [], SlotBins). sst_getmaxsequencenumber(Pid) -> gen_fsm:sync_send_event(Pid, get_maxsequencenumber, infinity). @@ -310,11 +315,7 @@ reader({get_kvrange, StartKey, EndKey, ScanWidth}, _From, State) -> State}; reader({get_slots, SlotList}, _From, State) -> SlotBins = read_slots(State#state.handle, SlotList), - FetchFun = - fun({SlotBin, SK, EK}, Acc) -> - Acc ++ binaryslot_trimmedlist(SlotBin, SK, EK) - end, - {reply, lists:foldl(FetchFun, [], SlotBins), reader, State}; + {reply, SlotBins, reader, State}; reader(get_maxsequencenumber, _From, State) -> Summary = State#state.summary, {reply, Summary#summary.max_sqn, reader, State}; @@ -353,15 +354,7 @@ delete_pending({get_kvrange, StartKey, EndKey, ScanWidth}, _From, State) -> ?DELETE_TIMEOUT}; delete_pending({get_slots, SlotList}, _From, State) -> SlotBins = read_slots(State#state.handle, SlotList), - FetchFun = - fun({SlotBin, SK, EK}, Acc) -> - Acc ++ binaryslot_trimmedlist(SlotBin, SK, EK) - end, - {reply, - lists:foldl(FetchFun, [], SlotBins), - delete_pending, - State, - ?DELETE_TIMEOUT}; + {reply, SlotBins, delete_pending, State, ?DELETE_TIMEOUT}; delete_pending(close, _From, State) -> leveled_log:log("SST07", [State#state.filename]), ok = file:close(State#state.handle),