<div dir="ltr">Hi All,<div><br></div><div> I just got a little burned. I was searching through an Array of symbols and integers (it is the PrimitiveTable from the VM), wanting to filter-out methods with a with a certain pragma. The code looks like:</div>
<div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">        </span>anArray doWithIndex:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>[:entry :index|</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>(self whichClassIncludesSelector: entry) ifNotNil:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>[:c| | m |</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>m := c >> entry.</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>(m pragmaAt: #option:) ifNotNil:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>[:pragma|</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>(initializationOptions at: (pragma arguments first) ifAbsent: [true]) ifFalse:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>[anArray at: index put: 0]]]]</div><div><br></div><div>the error was a keyNotFound error for c >> entry. Turns out entry was the integer 306, a code for a quick primitive that returns some inst var. The question is why did (self whichClassIncludesSelector: entry) evaluate to other than nil given that 306 is /not/ a selector in any of the classes from self on up. Well, it's MethodDictionary's use of pointsTo: that is at fault:</div>
<div><br></div><div><div>MethodDictionary>>includesKey: aSymbol</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"This override assumes that pointsTo is a fast primitive"</div><div><br>
</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>aSymbol ifNil: [^ false].</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>^ self pointsTo: aSymbol</div></div><div><br></div><div>
<div>ProtoObject>>pointsTo: anObject</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"This method returns true if self contains a pointer to anObject,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>and returns false otherwise"</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span><primitive: 132></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>1 to: self class instSize do:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>[:i | (self instVarAt: i) == anObject ifTrue: [^ true]].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>1 to: self basicSize do:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>[:i | (self basicAt: i) == anObject ifTrue: [^ true]].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>^ false</div></div><div><div><br></div><div>Turns out that 306 was the tally of one of the method dictionaries along self's superclass chain. This seems to be to be completely bogus. Do we really need crude performance hacks like this any more?</div>
-- <br>best,<div>Eliot</div>
</div></div></div>