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.
This commit is contained in:
parent
60af669400
commit
793f8e3a3a
1 changed files with 2 additions and 7 deletions
|
@ -265,14 +265,9 @@ cleanup_tree(Tree) ->
|
||||||
%% Various Helper routines
|
%% 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}) ->
|
open_dicts_with_keys(#state { open = Open}) ->
|
||||||
keysum_of_dicts(Open) > 0.
|
lists:any(fun({_, D}) -> dict:size(D) > 0 end,
|
||||||
|
dict:to_list(Open)).
|
||||||
keysum_of_dicts(DictOfDict) ->
|
|
||||||
Dicts = [ V || {_, V} <- dict:to_list(DictOfDict)],
|
|
||||||
lists:sum([dict:size(D) || D <- Dicts]).
|
|
||||||
|
|
||||||
open_dicts(#state { open = Open}) ->
|
open_dicts(#state { open = Open}) ->
|
||||||
dict:size(Open) > 0.
|
dict:size(Open) > 0.
|
||||||
|
|
Loading…
Reference in a new issue