diff options
author | Hans Bolinder <[email protected]> | 2019-04-25 09:02:09 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2019-05-03 09:57:17 +0200 |
commit | 7ac51a967ecf75d692b40d6fac62f838d4ae510c (patch) | |
tree | 644f16f708ebb1fb45599a62fe214b0bf7b8f58c /lib | |
parent | 23f600ad30107cc77265ce7cab35d052857768b3 (diff) | |
download | otp-7ac51a967ecf75d692b40d6fac62f838d4ae510c.tar.gz otp-7ac51a967ecf75d692b40d6fac62f838d4ae510c.tar.bz2 otp-7ac51a967ecf75d692b40d6fac62f838d4ae510c.zip |
stdlib: Optimize printing of maps a bit
Diffstat (limited to 'lib')
-rw-r--r-- | lib/stdlib/src/io_lib.erl | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl index 2b5a374cf2..21d66c5529 100644 --- a/lib/stdlib/src/io_lib.erl +++ b/lib/stdlib/src/io_lib.erl @@ -412,14 +412,25 @@ write_port(Port) -> write_ref(Ref) -> erlang:ref_to_list(Ref). +write_map(_, 1, _E) -> "#{}"; write_map(Map, D, E) when is_integer(D) -> - [$#,${,write_map_body(maps:to_list(Map), D, D - 1, E),$}]. + I = maps:iterator(Map), + case maps:next(I) of + {K, V, NextI} -> + D0 = D - 1, + W = write_map_assoc(K, V, D0, E), + [$#,${,[W | write_map_body(NextI, D0, D0, E)],$}]; + none -> "#{}" + end. -write_map_body(_, 1, _D0, _E) -> "..."; -write_map_body([], _, _D0, _E) -> []; -write_map_body([{K,V}], _D, D0, E) -> write_map_assoc(K, V, D0, E); -write_map_body([{K,V}|KVs], D, D0, E) -> - [write_map_assoc(K, V, D0, E),$, | write_map_body(KVs, D - 1, D0, E)]. +write_map_body(_, 1, _D0, _E) -> ",..."; +write_map_body(I, D, D0, E) -> + case maps:next(I) of + {K, V, NextI} -> + W = write_map_assoc(K, V, D0, E), + [$,,W|write_map_body(NextI, D - 1, D0, E)]; + none -> "" + end. write_map_assoc(K, V, D, E) -> [write1(K, D, E)," => ",write1(V, D, E)]. |