[squeak-dev] Stream nextPutAll: with an OrderedCollection go boom

Levente Uzonyi leves at caesar.elte.hu
Tue Mar 30 20:05:02 UTC 2021


Hi Tim,

On Tue, 30 Mar 2021, tim Rowledge wrote:

> I spotted a previous mention of this in the old maillist archives but it is still a current failure - 
>
> 	(OrderedCollection
> 		streamContents:
> 			[:strm |
> 				strm
> 					nextPutAll: (OrderedCollection with: 1 ) ])
>
> Boom!

I still agree with my previous answers[1]: don't do that. 
Just use OrderedCollection's own API if you want to build a collection.

>
> It's fine if we add asArray
>
> I'm suspicious of WriteStream>>#nextPutAll: making the assumption that SequenceableCollection>>#replaceFrom:to:with:startingAt: is always ok. Clearly not for OrderedCollection...
>
> Looks to me that we need to make OrderedCollection not pass the check for the 'fast path'? How about changing the #isBits test for a more capability oriented #canAcceptFastPathNextPut ?

There's no need to change anything there to support a bad pattern. If you 
really-really want to make it work, just override #new:streamContents::

OrderedCollection class >> new: newSize streamContents: blockWithArg

 	| contents |
 	contents := self arrayType new: newSize streamContents: blockWithArg.
 	^self basicNew
 		setContents: contents;
 		yourself


Levente

[1] http://forum.world.st/streamContents-on-OrderedCollection-broken-td4760369.html

>
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> A bug in the code is worth two in the documentation.


More information about the Squeak-dev mailing list