The Trunk: Collections-nice.340.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-nice.340.mcz

commits-2
Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.340.mcz

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

Name: Collections-nice.340
Author: nice
Time: 16 March 2010, 11:16:54.234 pm
UUID: 1d3154f5-018f-4624-a9e5-12b7349558b7
Ancestors: Collections-ul.339

Generalize stream protocol #readInto:startingAt:count:
It's the same as #next:into:startingAt: but avoid a copy and rather answer number of elements read.

=============== Diff against Collections-ul.339 ===============

Item was added:
+ ----- Method: ReadStream>>readInto:startingAt:count: (in category 'accessing') -----
+ readInto: aCollection startingAt: startIndex count: n
+ "Read n objects into the given collection.
+ Return number of elements that have been read."
+ | max |
+ max := (readLimit - position) min: n.
+ aCollection
+ replaceFrom: startIndex
+ to: startIndex+max-1
+ with: collection
+ startingAt: position+1.
+ position := position + max.
+ ^max!

Item was added:
+ ----- Method: NullStream>>readInto:startingAt:count: (in category 'reading') -----
+ readInto: aCollection startingAt: startIndex count: n
+ "Read n objects into the given collection.
+ Return number of elements that have been read."
+
+ position := position + n.
+ ^n!

Item was added:
+ ----- Method: PositionableStream>>readInto:startingAt:count: (in category 'accessing') -----
+ readInto: aCollection startingAt: startIndex count: n
+ "Read n objects into the given collection.
+ Return number of elements that have been read."
+ | obj |
+ 0 to: n - 1 do: [:i |
+ (obj := self next) == nil ifTrue: [^i].
+ aCollection at: startIndex + i put: obj].
+ ^n!

Item was added:
+ ----- Method: RWBinaryOrTextStream>>readInto:startingAt:count: (in category 'as yet unclassified') -----
+ readInto: aCollection startingAt: startIndex count: n
+ "Read n objects into the given collection.
+ Return number of elements that have been read."
+ "Overriden for efficiency"
+ | max |
+ max := (readLimit - position) min: n.
+ aCollection
+ replaceFrom: startIndex
+ to: startIndex+max-1
+ with: collection
+ startingAt: position+1.
+ position := position + max.
+ ^max!

Item was changed:
  ----- Method: PositionableStream>>next:into:startingAt: (in category 'accessing') -----
  next: n into: aCollection startingAt: startIndex
  "Read n objects into the given collection.
+ Return aCollection or a partial copy if less than n elements have been read."
+
+ | count |
+ count := self readInto: aCollection startingAt: startIndex count: n.
+ count = n
+ ifTrue:[ ^aCollection ]
+ ifFalse:[ ^aCollection copyFrom: 1 to: startIndex + count - 1 ]!
- Return aCollection or a partial copy if less than
- n elements have been read."
- | obj |
- 0 to: n-1 do:[:i|
- (obj := self next) == nil ifTrue:[^aCollection copyFrom: 1 to: startIndex+i-1].
- aCollection at: startIndex+i put: obj].
- ^aCollection!