aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src/io_lib_pretty.erl
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2018-04-09 12:22:11 +0200
committerHans Bolinder <[email protected]>2018-04-25 12:29:20 +0200
commitd3f0d1785e5847031f21484ca99c503c6ef704b8 (patch)
treecdd24ca4fd1c072fbec30671dfd09906ccd4c10b /lib/stdlib/src/io_lib_pretty.erl
parentbc38638a3633e028944d142150511fbcdd86cc92 (diff)
downloadotp-d3f0d1785e5847031f21484ca99c503c6ef704b8.tar.gz
otp-d3f0d1785e5847031f21484ca99c503c6ef704b8.tar.bz2
otp-d3f0d1785e5847031f21484ca99c503c6ef704b8.zip
stdlib: io_lib{_pretty}: Avoid tuple_to_list when possible
Diffstat (limited to 'lib/stdlib/src/io_lib_pretty.erl')
-rw-r--r--lib/stdlib/src/io_lib_pretty.erl35
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/stdlib/src/io_lib_pretty.erl b/lib/stdlib/src/io_lib_pretty.erl
index 656d2ddd41..785c602ac0 100644
--- a/lib/stdlib/src/io_lib_pretty.erl
+++ b/lib/stdlib/src/io_lib_pretty.erl
@@ -618,11 +618,24 @@ print_length_tuple(Tuple, 1, _T, RF, Enc, Str) ->
More = fun(T1, Dd) -> ?FUNCTION_NAME(Tuple, 1+Dd, T1, RF, Enc, Str) end,
{"{...}", 5, 3, More};
print_length_tuple(Tuple, D, T, RF, Enc, Str) ->
- L = print_length_list1(tuple_to_list(Tuple), D, tsub(T, 2), RF, Enc, Str),
+ L = print_length_tuple1(Tuple, 1, D, tsub(T, 2), RF, Enc, Str),
IsTagged = is_atom(element(1, Tuple)) and (tuple_size(Tuple) > 1),
{Len, Dots} = list_length(L, 2, 0),
{{tuple,IsTagged,L}, Len, Dots, no_more}.
+print_length_tuple1(Tuple, I, _D, _T, _RF, _Enc, _Str)
+ when I > tuple_size(Tuple) ->
+ [];
+print_length_tuple1(Tuple, I, D, T, RF, Enc, Str) when D =:= 1; T =:= 0->
+ More = fun(T1, Dd) -> ?FUNCTION_NAME(Tuple, I, D+Dd, T1, RF, Enc, Str) end,
+ {dots, 3, 3, More};
+print_length_tuple1(Tuple, I, D, T, RF, Enc, Str) ->
+ E = element(I, Tuple),
+ T1 = tsub(T, 1),
+ {_, Len1, _, _} = Elem1 = print_length(E, D - 1, T1, RF, Enc, Str),
+ T2 = tsub(T1, Len1),
+ [Elem1 | print_length_tuple1(Tuple, I + 1, D - 1, T2, RF, Enc, Str)].
+
print_length_record(Tuple, 1, _T, RF, RDefs, Enc, Str) ->
More = fun(T1, Dd) ->
?FUNCTION_NAME(Tuple, 1+Dd, T1, RF, RDefs, Enc, Str)
@@ -631,24 +644,28 @@ print_length_record(Tuple, 1, _T, RF, RDefs, Enc, Str) ->
print_length_record(Tuple, D, T, RF, RDefs, Enc, Str) ->
Name = [$# | write_atom(element(1, Tuple), Enc)],
NameL = string:length(Name),
- Elements = tl(tuple_to_list(Tuple)),
T1 = tsub(T, NameL+2),
- L = print_length_fields(RDefs, D - 1, T1, Elements, RF, Enc, Str),
+ L = print_length_fields(RDefs, D - 1, T1, Tuple, 2, RF, Enc, Str),
{Len, Dots} = list_length(L, NameL + 2, 0),
{{record, [{Name,NameL} | L]}, Len, Dots, no_more}.
-print_length_fields([], _D, _T, [], _RF, _Enc, _Str) ->
+print_length_fields([], _D, _T, Tuple, I, _RF, _Enc, _Str)
+ when I > tuple_size(Tuple) ->
[];
-print_length_fields(Term, D, T, Es, RF, Enc, Str) when D =:= 1; T =:= 0 ->
+print_length_fields(Term, D, T, Tuple, I, RF, Enc, Str)
+ when D =:= 1; T =:= 0 ->
More = fun(T1, Dd) ->
- ?FUNCTION_NAME(Term, D+Dd, T1, Es, RF, Enc, Str)
+ ?FUNCTION_NAME(Term, D+Dd, T1, Tuple, I, RF, Enc, Str)
end,
{dots, 3, 3, More};
-print_length_fields([Def | Defs], D, T, [E | Es], RF, Enc, Str) ->
- Field1 = print_length_field(Def, D - 1, tsub(T, 1), E, RF, Enc, Str),
+print_length_fields([Def | Defs], D, T, Tuple, I, RF, Enc, Str) ->
+ E = element(I, Tuple),
+ T1 = tsub(T, 1),
+ Field1 = print_length_field(Def, D - 1, T1, E, RF, Enc, Str),
{_, Len1, _, _} = Field1,
+ T2 = tsub(T1, Len1),
[Field1 |
- print_length_fields(Defs, D - 1, tsub(T, Len1 + 1), Es, RF, Enc, Str)].
+ print_length_fields(Defs, D - 1, T2, Tuple, I + 1, RF, Enc, Str)].
print_length_field(Def, D, T, E, RF, Enc, Str) ->
Name = write_atom(Def, Enc),