Collection.st
changeset 169 1a3042b58fb9
parent 155 edd7fc34e104
child 201 1deff0d47f37
--- a/Collection.st	Fri Oct 28 02:20:19 1994 +0100
+++ b/Collection.st	Fri Oct 28 02:21:17 1994 +0100
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.17 1994-10-10 00:22:39 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.18 1994-10-28 01:21:17 claus Exp $
 '!
 
 !Collection class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.17 1994-10-10 00:22:39 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.18 1994-10-28 01:21:17 claus Exp $
 "
 !
 
@@ -792,7 +792,7 @@
 !Collection methodsFor:'printing & storing'!
 
 maxPrint
-    "the print-limit; printOn: will not produce more output
+    "the print-limit; printOn: will try to not produce more output
      than the limit defined here."
 
     ^ 5000
@@ -802,7 +802,7 @@
     "common code for printString and displayString; they only differ in
      the print-message sent to the elements"
 
-    |thisString buffer count string noneYet total|
+    |thisString buffer count string noneYet total limit|
 
     thisContext isRecursive ifTrue:[
 	Transcript showCr:'Error: print/storeString of self referencing collection.'.
@@ -814,6 +814,8 @@
     buffer := ''.
     count := 0.
     total := 0.
+    limit := self maxPrint.
+
     self do: [:element |
 	thisString := element perform:aSelector.
 	noneYet ifTrue:[
@@ -829,13 +831,13 @@
 	    count := 0
 	].
 	total := total + 1.
-	(total > self maxPrint) ifTrue:[
+	(total > limit) ifTrue:[
 	    string := string , buffer , '... )'.
-	    ^string
+	    ^ string
 	]
     ].
     string := string , buffer , ')'.
-    ^string
+    ^ string
 !
 
 displayString
@@ -847,10 +849,10 @@
 printOn:aStream
     "append a user readable representation of the receiver to aStream.
      The text appended is not meant to be read back for reconstruction of
-     the receiver.
+     the receiver. Also, this method limits the size of generated string.
     "
 
-    |limit firstOne noMore string|
+    |limit firstOne string|
 
     thisContext isRecursive ifTrue:[
 	Transcript showCr:'Error: printOn: of self referencing collection.'.
@@ -862,36 +864,37 @@
     aStream nextPutAll:self class name.
     aStream nextPut:$(.
     firstOne := true.
-    noMore := false.
+
     self do:[:element |
-	noMore ifFalse:[
-	    firstOne ifFalse:[
-		aStream space
-	    ] ifTrue:[
-		firstOne := false
-	    ].
-	    (limit <= 0) ifTrue:[
-		aStream nextPutAll:'...etc...)'.
-		noMore := true
-	    ] ifFalse:[
+	firstOne ifFalse:[
+	    aStream space
+	] ifTrue:[
+	    firstOne := false
+	].
+	(limit <= 0) ifTrue:[
+	    aStream nextPutAll:'...etc...)'.
+	    ^ self
+	] ifFalse:[
 "/ old code, worked only on positionable streams
 "/
 "/              pos1 := aStream position.
 "/              element printOn:aStream.
 "/              limit := limit - (aStream position - pos1)
-		string := element printString.
-		aStream nextPutAll:string.
-		limit := limit - string size.
-	    ]
+
+	    string := element printString.
+	    aStream nextPutAll:string.
+	    limit := limit - string size.
 	].
     ].
     aStream nextPut:$)
 
     "
      #(1 2 3 'hello' $a) printOn:Transcript
-
+     (Array new:100000) printOn:Transcript
+     (Array new:100000) printString size 
      (Dictionary new at:#hello put:'world'; yourself) printOn:Transcript
-
+    "
+    "
      |a| 
      a := Array new:3. 
      a at:2 put:a.