aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/src/dialyzer_utils.erl
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2017-03-14 10:46:38 +0100
committerHans Bolinder <[email protected]>2017-06-13 13:40:26 +0200
commitce6fe3c77b31e6c0fcb13d347c3fcbbedfd544e7 (patch)
tree6b9c0adcc868f2b804129ae97f3fe85b1af693fe /lib/dialyzer/src/dialyzer_utils.erl
parent020a8817caca2684f8241dc5f9c84a37d53b4ff7 (diff)
downloadotp-ce6fe3c77b31e6c0fcb13d347c3fcbbedfd544e7.tar.gz
otp-ce6fe3c77b31e6c0fcb13d347c3fcbbedfd544e7.tar.bz2
otp-ce6fe3c77b31e6c0fcb13d347c3fcbbedfd544e7.zip
dialyzer: Improve compression of an ETS table
Diffstat (limited to 'lib/dialyzer/src/dialyzer_utils.erl')
-rw-r--r--lib/dialyzer/src/dialyzer_utils.erl22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl
index 7eaa03ec30..0dbb2bcf0a 100644
--- a/lib/dialyzer/src/dialyzer_utils.erl
+++ b/lib/dialyzer/src/dialyzer_utils.erl
@@ -39,6 +39,7 @@
sets_filter/2,
src_compiler_opts/0,
refold_pattern/1,
+ ets_tab2list/1,
parallelism/0,
family/1
]).
@@ -989,6 +990,27 @@ label(Tree) ->
%%------------------------------------------------------------------------------
+-spec ets_tab2list(ets:tid()) -> list().
+
+%% Deletes the contents of the table. Use:
+%% ets_tab2list(T), ets:delete(T)
+%% instead of:
+%% ets:tab2list(T), ets:delete(T)
+%% to save some memory at the expense of somewhat longer execution time.
+ets_tab2list(T) ->
+ tab2list(ets:first(T), T, []).
+
+tab2list('$end_of_table', T, A) ->
+ case ets:first(T) of % no safe_fixtable()...
+ '$end_of_table' -> A;
+ Key -> tab2list(Key, T, A)
+ end;
+tab2list(Key, T, A) ->
+ Vs = ets:lookup(T, Key),
+ Key1 = ets:next(T, Key),
+ ets:delete(T, Key),
+ tab2list(Key1, T, Vs ++ A).
+
-spec parallelism() -> integer().
parallelism() ->