[m-rev.] for review: limited_deconstruct in the basic prettyprinters

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Jun 22 13:29:23 AEST 2001


For review by Mark.

browser/browse.m:
	Make the prettyprinters in this file use limited_deconstruct to avoid
	performance problems with large arrays.

Zoltan.

cvs diff: Diffing .
Index: browse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/browse.m,v
retrieving revision 1.20
diff -u -b -r1.20 browse.m
--- browse.m	2001/06/22 03:14:24	1.20
+++ browse.m	2001/06/22 03:24:57
@@ -492,18 +492,22 @@
 :- pred term_to_string_2(univ, int, int, int, int, int, string).
 :- mode term_to_string_2(in, in, in, out, in, in, out) is det.
 term_to_string_2(Univ, MaxSize, CurSize, NewSize, MaxDepth, CurDepth, Str) :-
-	( ( (CurSize >= MaxSize) ; (CurDepth >= MaxDepth) ) ->
-		% Str = "...",
-		term_compress(Univ, Str),
-		NewSize = CurSize
-	;
-		deconstruct(univ_value(Univ), Functor, _Arity, Args),
+	(
+		CurSize < MaxSize,
+		CurDepth < MaxDepth,
+		limited_deconstruct(univ_value(Univ), MaxSize, Functor,
+			_Arity, Args)
+	->
 		CurSize1 is CurSize + 1,
 		CurDepth1 is CurDepth + 1,
 		term_to_string_list(Args, MaxSize, CurSize1, NewSize,
 			MaxDepth, CurDepth1, ArgStrs),
 		brack_args(ArgStrs, BrackArgsStr),
 		string__append_list([Functor, BrackArgsStr], Str)
+	;
+		% Str = "...",
+		term_compress(Univ, Str),
+		NewSize = CurSize
 	).
 
 :- pred term_to_string_list(list(univ), int, int, int, int, int, list(string)).
@@ -549,7 +553,7 @@
 :- pred term_compress(univ, string).
 :- mode term_compress(in, out) is det.
 term_compress(Univ, Str) :-
-	deconstruct(univ_value(Univ), Functor, Arity, _Args),
+	functor(univ_value(Univ), Functor, Arity),
 	( Arity = 0 ->
 		Str = Functor
 	;
@@ -557,7 +561,6 @@
 		append_list([Functor, "/", ArityS], Str)
 	).
 	
-
 %---------------------------------------------------------------------------%
 %
 % Print using the pretty printer from the standard library.
@@ -593,12 +596,12 @@
 :- mode term_to_string_verbose_2(in, in, in, out, in, in, out) is det.
 term_to_string_verbose_2(Univ, MaxSize, CurSize, NewSize,
 		MaxDepth, CurDepth, Frame) :-
-	( ((CurSize >= MaxSize) ; (CurDepth >= MaxDepth)) ->
-		term_compress(Univ, Line),
-		Frame = [Line],
-		NewSize = CurSize
-	;
-		deconstruct(univ_value(Univ), Functor, _Arity, Args),
+	(
+		CurSize < MaxSize,
+		CurDepth < MaxDepth,
+		limited_deconstruct(univ_value(Univ), MaxSize, Functor,
+			_Arity, Args)
+	->
 		CurSize1 is CurSize + 1,
 		CurDepth1 is CurDepth + 1,
 		ArgNum = 1,
@@ -606,6 +609,10 @@
 			MaxSize, CurSize1, NewSize,
 			MaxDepth, CurDepth1, ArgsFrame),
 		frame__vglue([Functor], ArgsFrame, Frame)
+	;
+		term_compress(Univ, Line),
+		Frame = [Line],
+		NewSize = CurSize
 	).
 
 :- pred term_to_string_verbose_list(list(univ), int, int, int, int,
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list