Mantis - Squeak
Viewing Issue Advanced Details
7269 Collections minor always 01-13-09 23:31 04-18-10 22:05
Keith_Hodges  
nicolas cellier  
normal  
closed  
fixed  
none    
none trunk  
0007269: OrderedCollection streamContents broken
OrderedCollection streamContents: [ :str | 200 timesRepeat: [ str nextPut: 1 ] ]

fails
related to 0002390closed nicolas cellier ReadWriteStream with an OrderedCollection bugs when growing 
 M7269-OrderedCollection-streaming-nice-test.1.cs [^] (1,475 bytes) 02-26-09 10:37
 M7269-OrderedCollection-streaming-nice-patch.1.cs [^] (1,128 bytes) 02-26-09 10:37

Notes
(0012924)
wiz   
01-16-09 03:45   
The culprit IMO is this:

(From 3.10.2)
'md 2/24/2006 19:50 WriteStream pastEndPut: {private}'

WriteStream>>pastEndPut: anObject
    "Grow the collection by creating a new bigger collection and then
    copy over the contents from the old one. We grow by doubling the size
    but the growth is kept between 20 and 1000000.
    Finally we put <anObject> at the current write position."

    | oldSize grownCollection |
    oldSize := collection size.
    grownCollection := collection class new: oldSize + ((oldSize max: 20) min: 1000000).
    collection := grownCollection replaceFrom: 1 to: oldSize with: collection startingAt: 1.
    writeLimit := collection size.
    collection at: (position := position + 1) put: anObject.
    "return the argument - added by kwl"
    ^ anObject

Obviously wired to assume an arrayed collection.

And it is assuming the responsibility of making a grown collection.
There needs to be language that lets the collection return a grown form of itself. WriteStream should be collection agnostic.

Either that or streamContents should be defined at the ArrayedCollection level and not the Sequential Collection level. Of course that would not still allow streaming contents on an ordered collection. But at least it wouldn't raise false hopes.
(0012988)
nicolas cellier   
02-24-09 11:21   
jerome, you mean delegate the grow operation to collection by sending a message like other st dialects do ?

collection := collection grownToSize: oldSize + ((oldSize max: 20) min: 1000000).

Good news, the message both:
- already exists
- will work with OrderedCollection (after applying 0007296 patch)

You can either use #ofSize: and do the copy yourself
Or use #forceTo:padding: which does the copy for you.
Unfortunately which padding element to use is not obvious:
    (collection species ofSize: 1) anyOne
is a good padding, but kind of overkill...


WriteStream>>pastEndPut: anObject
    "Grow the collection by creating a new bigger collection and then
    copy over the contents from the old one. We grow by doubling the size
    but the growth is kept between 20 and 1000000.
    Finally we put <anObject> at the current write position."

    | oldSize defaultElement |
    oldSize := collection size.
    defaultElement := (collection species ofSize: 1) anyOne.
    collection := collection forceTo: oldSize + ((oldSize max: 20) min: 1000000) paddingWith: defaultElement.
    writeLimit := collection size.
    collection at: (position := position + 1) put: anObject.
    ^ anObject
(0012991)
wiz   
02-26-09 02:50   
Hi nicolas,

Thanks for chiming in.


> jerome, you mean delegate the grow operation to collection by sending a message like other st dialects do ?

That's what I had in mind.
I don't know other dialects.
What do they send? Are they in agreement?

I have not thought beyond my first comment on this.

If you can think this thru to a solution that would be great.
(0012992)
nicolas cellier   
02-26-09 10:40   
"fix begin"
Installer mantis ensureFix: 7296.
Installer mantis bug: 7269 fix: 'M7269-OrderedCollection-streaming-nice-patch.1.cs'.
"fix test"
Installer mantis bug: 7269 fix: 'M7269-OrderedCollection-streaming-nice-test.1.cs'.
"fix end"
(0013270)
nicolas cellier   
08-24-09 20:08   
Fixed in http://source.squeak.org/trunk/Collections-nice.116.mcz [^]