问题描述
-
LLVM是否在可能的情况下自动将Objective-C方法转换为内联函数?
Does LLVM automatically convert Objective-C methods to inline functions when possible?
(也就是说,是否可以为代码块创建一个Objective-C方法,否则可以内联粘贴?)
(I.e., is it just as performant to create an Objective-C method for a block of code that you could otherwise paste inline?)
如果LLVM没有执行此优化,为什么不呢?如果是这样,(a)是否必须设置某些构建设置才能实现? (b)如何判断是否将内联Objective-C方法?
If LLVM doesn't perform this optimization, why not? If it does, (a) are there certain build settings I must set for this to happen? (b) How can I tell if an Objective-C method will be inlined?
推荐答案
否,因为在Obj-C运行时的上下文中无法知道是否可以执行这些优化.要记住的是,Obj-C方法是由消息发送调用的,这些消息不仅可以来自[myObject doSomething]
语法,而且还可以来自其他消息.
No, because its impossible to know in the context of the Obj-C runtime if those kind of optimizations can be performed. The thing to remember is that Obj-C methods are invoked by a message send, these messages can come from more than just the [myObject doSomething]
syntax.
考虑[obj performSelector:NSSelectorFromString(@"hello")]
这可能发生的事实意味着不可能内联任何方法.
Consider [obj performSelector:NSSelectorFromString(@"hello")]
the fact that this can happen means that it would be impossible to ever inline any method.
当类收到消息时,还会发生一系列事件,这些事件可以重新路由,甚至更改正在发送的消息.这透明地发生在消息发送的下方.
There is also a chain of events that happens when a message is received by a class, these events can reroute, or even change the message that is being sent. This happens transparently underneath the message send.
这篇关于LLVM是否将Objective-C方法转换为内联函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!