Probably speed. If you look at implementers of #next:putAll:startingAt:
you'll see that there are much faster ways of dumping 20K of bytes into
a file than going byte by byte. But commonly the assumption for the fast
alternatives is that the source collection is sequenceable.
Damien Cassou wrote:
> Hi,
>
> browsing through the source code, i found the following methods with an
> implementation I don't understand:
>
>
> Stream>>nextPutAll: aCollection
> aCollection isSequenceable
> ifTrue: [self next: aCollection size putAll: aCollection startingAt: 1]
> ifFalse: [aCollection do: [:v | self nextPut: v]].
> ^ aCollection
>
> and:
>
> Stream>>next: anInteger putAll: aSequenceableCollection startingAt:
> startIndex
> startIndex to: startIndex + anInteger - 1 do:
> [:index | self nextPut: (aSequenceableCollection at: index)].
> ^aSequenceableCollection
>
>
> I don't understand the test within #nextPutAll:. Why is it necessary ?
> Why not simply:
>
> Stream>>nextPutAll: aCollection
> aCollection do: [:v | self nextPut: v].
> ^ aCollection
>
> In fact, Squeak implement it like this.
>
>
> Thank you
>
>