[Pharo-project] Small improvement for WriteStream >> nextPutAll:

Mariano Martinez Peck marianopeck at gmail.com
Sun Jan 8 08:46:32 EST 2012

Hi guys. Some time ago Henry spot to us a small improvement for WriteStream
>> nextPutAll: that we are using in Fuel, but I think it can be general.
Henry comment was exactly:

*Also: For variableBytes classes, if you rewrite:

nextPutAll: aCollection

     | newEnd |
     collection class instSpec == aCollection class instSpec ifFalse:
         [^ super nextPutAll: aCollection ].

     newEnd := position + aCollection size.
     newEnd > writeLimit ifTrue:
         [self growTo: newEnd + 10].

     collection replaceFrom: position+1 to: newEnd  with:
aCollectionstartingAt: 1.
     position := newEnd.

    ^ aCollection

You can now pass all variableByte classes (Like ByteString) directly to a
stream with a ByteArray collection, and the replaceFrom:to:with:*
*startingAt: primitive will work correctly, just like the file primitive
This means you don't need special Serializers for these either,  using
f.ex. clunky nextStringPutAll: methods with manual asByteArray conversions.*

So...if you agree, I can commit the patch.

Let me know.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20120108/7f835f9e/attachment-0001.html>

More information about the Pharo-dev mailing list