The Trunk: Collections-ar.295.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-ar.295.mcz

commits-2
Andreas Raab uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ar.295.mcz

==================== Summary ====================

Name: Collections-ar.295
Author: ar
Time: 6 February 2010, 11:29:54.991 am
UUID: 3215e783-a077-f743-a43b-2ecea69031aa
Ancestors: Collections-ul.294, Collections-mtf.291

Merging Collections-mtf.291:

7219: Improve Streams Usage Readability
http://bugs.squeak.org/view.php?id=7219

Adds << to streams to be mostly like nextPutAll, but uses putOn: so that it works with any object.

=============== Diff against Collections-ul.294 ===============

Item was added:
+ ----- Method: ByteArray>>putOn: (in category 'streaming') -----
+ putOn: aStream
+
+ aStream nextPutAll: self
+ !

Item was added:
+ ----- Method: SequenceableCollection>>putOn: (in category 'streaming') -----
+ putOn: aStream
+
+ self do: [ :each | each putOn: aStream ]!

Item was added:
+ ----- Method: Stream>><< (in category 'readability') -----
+ << items
+
+   items putOn: self.
+
+ ^ self!

Item was added:
+ ----- Method: WriteStream>><< (in category 'printing') -----
+ << aCollection
+ "we want a readable version of nextPutAll however it may be difficult to fully recreate nextPutAll:
+ for all the different types of stream. Rather then simply send to nextPutAll:
+ we handle the String (or ByteArray) argument
+ as fast as possible - the rest we delegate to putOn: This means that we handle single characters and bytes
+ whereas nextPutAll: is only for sequencable collections.
+ .
+ Note this may not work in every case that nextPutAll: does subject to extensive testing,
+ but it should work in the important cases"
+
+ | newEnd |
+ collection class == aCollection class ifFalse:
+ [ aCollection putOn: self. ^ self ].
+
+ newEnd := position + aCollection size.
+ newEnd > writeLimit ifTrue:
+ [self growTo: newEnd + 10].
+
+ collection replaceFrom: position+1 to: newEnd  with: aCollection startingAt: 1.
+ position := newEnd.
+
+ !