|
|
|
|
|
by mojuba
2437 days ago
|
|
Objective-C's OO model is far more dynamic than you may realize. There're no guarantees even on the object reference type at run time, i.e. that the method you are calling will be applied to an object of a specific type or compatible. ObjC is very permissive in this regard, though it can give warnings in certain cases but they are never 100% precise (from my experience anyway). You could run analysis on the entire end product and still be unsure of what's going to happen at run time. |
|
The interesting thing is that by inlining, for the inline case you will often gain additional type information. E.g. to take an example from Ruby, since I don't know Objective C very well. In isolation you have no way of telling what type "foo + 1 + 2 + 3" will return, as it depends entirely on "foo". But lets say most call-sites calling the method where this expression is found passes an integer.
If I can guarantee that "foo + 1" is an Integer addition, then I know it will return an Integer, and so I know the same addition method will be used for the next addition (and by extension the next as well), so I can turn the above into the following Ruby-ish pseudo-code instead:
Even when you can't safely inline the actual calls, you can often elide checks or resort to more specialized method caching.