Mantis - Squeak
Viewing Issue Advanced Details
7296 Collections minor always 02-19-09 03:24 04-18-10 22:05
lucian3  
nicolas cellier  
normal  
closed 3.10.2  
fixed  
none    
none trunk  
0007296: forceTo:paddingWith: doesn't work with OrderedCollections
Evaluate in a workspace and you should get an error indicating you attempted to access a non-existent element in an OrderedCollection:

oc := #(1 2 3) asOrderedCollection.
oc forceTo: 10 paddingWith: nil.
 M7296-forceTopadding-nice-test.1.cs [^] (1,193 bytes) 02-24-09 10:49
 M7296-forceTopadding-nice-patch.1.cs [^] (913 bytes) 02-24-09 10:51
 M7296-forceTopadding-nice-test.2.cs [^] (1,935 bytes) 02-26-09 10:57
 M7296-forceTopadding-nice-patch.2.cs [^] (1,470 bytes) 02-26-09 11:06

Notes
(0012986)
nicolas cellier   
02-24-09 10:30   
Classical distinction between size and capacity...
Some messages assume #new: will answer a collection filled with nil.
This is true in ArrayedCollection but not in all SequenceableCollection.

One solution would be to use a replacement message for #new:
#ofSize: is the right message in this case.
But IMO, #new:withAll: would be also a good one.

forceTo: length paddingWith: elem
    "Force the length of the collection to length, padding
    if necessary with elem. Note that this makes a copy."

    | newCollection copyLen |
    newCollection := self species new: length withAll: elem.
    copyLen := self size min: length.
    newCollection replaceFrom: 1 to: copyLen with: self startingAt: 1.
    ^ newCollection

Of course, #new:withAll: has to be implemented in OrderedCollection class
new: anInteger withAll: anObject
    ^ super basicNew setContents: (Array new: anInteger withAll: anObject)
(0012987)
nicolas cellier   
02-24-09 10:52   
"fix begin"
Installer mantis bug: 7296 fix: 'M7296-forceTopadding-nice-patch.1.cs'.
"fix test"
Installer mantis bug: 7296 fix: 'M7296-forceTopadding-nice-test.1.cs'.
"fix end"
(0012993)
nicolas cellier   
02-26-09 11:07   
I forgot to change forceTo:paddingStartWith: which suffer from same problem.
This is why a version 2 has been uploaded.
I used ofSize: this time just to vary pleasure.
(0012994)
nicolas cellier   
02-26-09 11:08   
"fix begin"
Installer mantis bug: 7296 fix: 'M7296-forceTopadding-nice-patch.2.cs'.
"fix test"
Installer mantis bug: 7296 fix: 'M7296-forceTopadding-nice-test.2.cs'.
"fix end"
(0013269)
nicolas cellier   
08-24-09 20:07   
Fixed in http://source.squeak.org/trunk/Collections-nice.115.mcz [^]