[squeak-dev] The Inbox: CollectionsTests-dtl.212.mcz

Levente Uzonyi leves at elte.hu
Sun Jan 19 17:06:37 UTC 2014


On Sun, 19 Jan 2014, Nicolas Cellier wrote:

> It's a bug. Let's remove the optimizatoin. If we really want it, this could be a implemented like
> 
> WriteStream>>sharedContents  | sz | ^(sz := position max: readLimit) = collection size ifTrue: [collection] ifFalse: [collection copyFrom: 1 to:
> sz]

#new:streamContents: is about optimization, nothing else. I think it's a 
better solution to set the stream to the end before comparing the position 
with the size, because I don't see any other possible use for
#sharedContents.


Levente

P.S.: Why is this an OrderedCollectionTest? It's not related to 
OrderedCollection at all.

> 
> 
> 2014/1/19 David T. Lewis <lewis at mail.msen.com>
>       This goes in the inbox because I am not sure if it should be treated
>       as a bug or as an acceptable limitation that needs to be documented.
>
>       Dave
> 
>
>       On Sun, Jan 19, 2014 at 03:43:45PM +0000, commits at source.squeak.org wrote:
>       > David T. Lewis uploaded a new version of CollectionsTests to project The Inbox:
>       > http://source.squeak.org/inbox/CollectionsTests-dtl.212.mcz
>       >
>       > ==================== Summary ====================
>       >
>       > Name: CollectionsTests-dtl.212
>       > Author: dtl
>       > Time: 19 January 2014, 10:43:43.125 am
>       > UUID: 6916414f-dda9-4b64-a4ee-f5f50aacd4c4
>       > Ancestors: CollectionsTests-dtl.211
>       >
>       > Add OrderedCollectionTest>>testStreamContentsPositioning.
>       >
>       > String class>>new:streamContents: optimizes performance by answering originalCollection in the case of a stream positioned to the
>       size of its original collection. This fails if the stream has been repositioned backwards to its original length.
>       >
>       > The optimization was introduced in Collections-ar.129 which merges Collections-ul.128 from inbox:
>       >
>       > - introduced #new:streamContents: in SequenceableCollection class. It's like #streamContents: but if you know the size of the new
>       collection this method doesn't copy the result.
>       > - updated SequenceableCollection class >> #streamContents: to use #new:streamContents:, kept the original default size 100.
>       >
>       > =============== Diff against CollectionsTests-dtl.211 ===============
>       >
>       > Item was added:
>       > + ----- Method: OrderedCollectionTest>>testStreamContentsPositioning (in category 'testStreaming') -----
>       > + testStreamContentsPositioning
>       > +     "String class>>new:streamContents: optimizes performance by answering the
>       > +     originalCollection in the case of a stream positioned to the size of the original
>       > +     collection. This fails if the stream has been repositioned backwards to its original
>       > +     length."
>       > +
>       > +     "(OrderedCollectionTest selector: #testStreamContentsPositioning) debug"
>       > +
>       > +     | s |
>       > +     s := String new: 10 streamContents: [ :strm |
>       > +                     strm nextPutAll: 'XXXXX'.
>       > +                     self assert: 'XXXXX' equals: strm contents.
>       > +                     strm nextPut: $X.
>       > +                     self assert: 'XXXXXX' equals: strm contents.
>       > +                     strm position: strm position - 1.
>       > +                     self assert: 'XXXXX' equals: strm contents.
>       > +                     strm nextPutAll: 'XXXXX'.
>       > +                     self assert: 'XXXXXXXXXX' equals: strm contents.
>       > +                     strm nextPut: $X.
>       > +                     self assert: 'XXXXXXXXXXX' equals: strm contents.
>       > +                     strm position: strm position - 1.
>       > +                     self assert: 'XXXXXXXXXX' equals: strm contents.
>       > +             ].
>       > +     self assert: 10 equals: s size.
>       > +     self assert: 'XXXXXXXXXX' equals: s.
>       > +
>       > +     !
>       >
> 
> 
> 
>


More information about the Squeak-dev mailing list