質問

  1. Will the typical compiler inline a C function that makes one or more Objective-C method calls? E.g.:

    NSUInteger AACStringGetLength(NSString *string)
    {
        return [string length];
    }
    
  2. Bonus points for a thorough proof with explanation.

  3. What other things besides recursion might prevent the compiler from inlining a C function?

役に立ちましたか?

解決

AACStringGetLength() can be inlined into its callers assuming the other requirements of inlining are satisfied. There's nothing about calls to Objective-C methods that prevents inlining of C functions.

Of course Objective-C methods cannot be inlined themselves, because the compiler cannot know that there is no unusual dynamic dispatch going on.

Things that can prevent inlining include:

  • the caller and callee are in different translation units (i.e. different source code files), unless you are using link-time optimization of some sort
  • the caller's code might end up "too big" after inlining according to the compiler's inlining heuristics
  • the callee performs control flow that is too complicated for the compiler's inlining machinery to handle so it gives up
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top