Exposing NSDictionary
While powerful, indexed ivars come with two caveats. First of all,
class_createInstancecan’t be used under ARC, so you’ll have to compile some parts of your class with-fno-objc-arcflag to make it shine. Secondly, the runtime doesn’t keep the indexed ivar size information anywhere. Even thoughdeallocwill clean everything up (as it callsfreeinternally), you should keep the storage size somewhere, assuming you use variable number of extra bytes.[…]
We already know
__NSDictionarySizesis some kind of array that stores different possible sizes of__NSDictionaryI.[…]
It turns out
__NSDictionaryIdoesn’t check if thekeypassed intoobjectForKey:isnil(and I’d argue this is a good design decision). Callinghashmethod onnilreturns0, which causes the class to compare key at index0withnil. This is important: it is the stored key that executes theisEqual:method, not the passed in key.
See also Exposing NSMutableArray.
1 Comment RSS · Twitter
[…] Previously: Exploring Swift Dictionary’s Implementation, Exposing NSDictionary. […]