[squeak-dev] The Trunk: Compression-nice.16.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Mar 16 22:18:20 UTC 2010


Nicolas Cellier uploaded a new version of Compression to project The Trunk:
http://source.squeak.org/trunk/Compression-nice.16.mcz

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

Name: Compression-nice.16
Author: nice
Time: 16 March 2010, 11:18:13.123 pm
UUID: 220aef1a-9452-46f3-95c0-38b57d9802aa
Ancestors: Compression-nice.15

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 Compression-nice.15 ===============

Item was added:
+ ----- Method: InflateStream>>readInto:startingAt:count: (in category 'accessing') -----
+ readInto: buffer startingAt: startIndex count: n
+ 	"Read n objects into the given collection. 
+ 	Return number of elements that have been read."
+ 	| c numRead count |
+ 	numRead := 0.
+ 	["Force decompression if necessary"
+ 	(c := self next) == nil 
+ 		ifTrue: [^numRead].
+ 	"Store the first value which provoked decompression"
+ 	buffer at: startIndex + numRead put: c.
+ 	numRead := numRead + 1.
+ 	"After collection has been filled copy as many objects as possible"
+ 	count := (readLimit - position) min: (n - numRead).
+ 	buffer 
+ 		replaceFrom: startIndex + numRead 
+ 		to: startIndex + numRead + count - 1 
+ 		with: collection 
+ 		startingAt: position+1.
+ 	position := position + count.
+ 	numRead := numRead + count.
+ 	numRead = n] whileFalse.
+ 	^n!




More information about the Squeak-dev mailing list