Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002143 [Squeak] Collections minor always 10-30-05 18:36 01-18-06 19:21
Reporter johnmci View Status public  
Assigned To
Priority normal Resolution fixed  
Status closed   Product Version
Summary 0002143: usage of second/third/fourth/fifth/etc
Description Use of method accessors that resolve to at: are expensive and contain uneeded code.

SequenceableCollection>>fifth for example
fifth
    "Answer the fifth element of the receiver.
    Raise an error if there are not enough elements."

    ^ self checkedAt: 5

SequenceableCollection>>checkedAt: index
    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: '

at: index
    "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
    whatIsAPrimitive."

    <primitive: 60>
    index isInteger ifTrue:
        [self class isVariable
            ifTrue: [self errorSubscriptBounds: index]
            ifFalse: [self errorNotIndexable]].
    index isNumber
        ifTrue: [^self at: index asInteger]
        ifFalse: [self errorNonIntegerIndex]

Additional Information 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

- Relationships

- Notes
(0003535 - 19 - 19 - 19 - 19 - 19 - 19)
MarcusDenker
01-18-06 19:21

will be in 3.9a6715
 

- Issue History
Date Modified Username Field Change
10-30-05 18:36 johnmci New Issue
10-30-05 18:36 johnmci File Added: JMMRemoveExtraIndexCheck.1.cs
01-18-06 19:21 MarcusDenker Status new => closed
01-18-06 19:21 MarcusDenker Note Added: 0003535
01-18-06 19:21 MarcusDenker Resolution open => fixed
01-18-06 19:21 MarcusDenker Fixed in Version  => 3.9


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
37 total queries executed.
30 unique queries executed.
Powered by Mantis Bugtracker