From 793f8e3a3ad091b123925cefdb8c86b4b4186b79 Mon Sep 17 00:00:00 2001 From: Jesper Louis Andersen Date: Sun, 8 Jan 2012 00:01:18 +0100 Subject: [PATCH] Optimize open dict check. A dict is open and with keys if its size is greater than 0. Go through the dicts one by one with lists:any/2 and use that to optimize the check. Ought to run faster than traversing the full set. --- test/lsm_btree_tests.erl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/lsm_btree_tests.erl b/test/lsm_btree_tests.erl index 8877e39..2558274 100644 --- a/test/lsm_btree_tests.erl +++ b/test/lsm_btree_tests.erl @@ -265,14 +265,9 @@ cleanup_tree(Tree) -> %% Various Helper routines %% ---------------------------------------------------------------------- -%% @todo optimize this call. You can fast-exit as soon as you know -%% there is a non-empty dict. open_dicts_with_keys(#state { open = Open}) -> - keysum_of_dicts(Open) > 0. - -keysum_of_dicts(DictOfDict) -> - Dicts = [ V || {_, V} <- dict:to_list(DictOfDict)], - lists:sum([dict:size(D) || D <- Dicts]). + lists:any(fun({_, D}) -> dict:size(D) > 0 end, + dict:to_list(Open)). open_dicts(#state { open = Open}) -> dict:size(Open) > 0.