[squeak-dev] The Inbox: CollectionsTests-dtl.212.mcz
Levente Uzonyi
leves at elte.hu
Sun Jan 19 20:42:07 UTC 2014
On Sun, 19 Jan 2014, David T. Lewis wrote:
> On Sun, Jan 19, 2014 at 06:06:37PM +0100, Levente Uzonyi wrote:
>> 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.
>
> Do you mean something like this?
>
> new: newSize streamContents: blockWithArg
> | stream p endPos |
> stream := WriteStream on: (self new: newSize).
> blockWithArg value: stream.
> p := stream position.
It doesn't matter what the current position of the stream is. If there's
data after the current position, then #contents will return it. So I think
this is how the method should be:
new: newSize streamContents: blockWithArg
| stream |
stream := WriteStream on: (self new: newSize).
blockWithArg value: stream.
stream setToEnd position = newSize
ifTrue: [ ^stream originalContents ]
ifFalse: [ ^stream contents ]
Levente
> endPos := stream setToEnd position.
> p = endPos
> ifTrue: [p = newSize
> ifTrue: [^ stream originalContents]]
> ifFalse: [stream position: p].
> ^ stream contents
>
>
> I'm not sure what that would do to the performance gains.
>
> Dave
>
>
>
More information about the Squeak-dev
mailing list
|