Mantis - Squeak
|Viewing Issue Advanced Details|
|ID:||Category:||Severity:||Reproducibility:||Date Submitted:||Last Update:|
|2143||Collections||minor||always||10-30-05 18:36||01-18-06 19:21|
|ETA:||none||Fixed in Version:||3.9|
|Summary:||0002143: usage of second/third/fourth/fifth/etc|
Use of method accessors that resolve to at: are expensive and contain uneeded code.
SequenceableCollection>>fifth for example
"Answer the fifth element of the receiver.
Raise an error if there are not enough elements."
^ self checkedAt: 5
index > self size ifTrue: [self error: 'not enough elements'].
^ self at: index
Note the index check, but then we fall into self at: which I believe all at: do an index anyways to protect us from disaster. I'll also note that foo fifth under an error condition would have raised error: 'not enough elements': versus saying foo at: which would have raised error: 'subscript is out of bounds: '
"Primitive. Assumes receiver is indexable. Answer the value of an
indexable element in the receiver. Fail if the argument index is not an
Integer or is out of bounds. Essential. See Object documentation
index isInteger ifTrue:
[self class isVariable
ifTrue: [self errorSubscriptBounds: index]
ifFalse: [self errorNotIndexable]].
ifTrue: [^self at: index asInteger]
ifFalse: [self errorNonIntegerIndex]
|Steps To Reproduce:|
I've included a changset to change the second/third/.../ninth methods to just invoke at:
method first is a bit different and I left it unaltered for now.
However one might look at first and see if the logic there is needed?
Some implementations invoke self emptyCheck, but is that any different than saying at: 1 ?
|Attached Files:||JMMRemoveExtraIndexCheck.1.cs [^] (1,695 bytes) 10-30-05 18:36|