简体   繁体   English

迅捷速度vs空抽出矩形

[英]Swift speed vs Empty Draw Rect

So i was reading Mike Ash's article on Swift speed where i encountered that if we have an empty function then a method call will not be made by Swift 所以我在阅读Mike Ash关于Swift速度的文章时,遇到了如果我们有一个空函数,那么Swift将不会进行方法调用

func test() {}

Then a call to test() basically would not be called by the compiler. 然后,编译器基本上不会调用对test()的调用。

Now if i remember correctly then Apple recommends against leaving an empty drawRect: method because it might hinder performance. 现在,如果我没记错的话,Apple建议不要保留一个空的drawRect:方法,因为它可能会影响性能。

Now my question is if an empty function is never called by the compiler then why against the empty drawRect: I was just curious. 现在我的问题是,如果编译器从未调用过空函数,那么为什么要反对空drawRect:我只是好奇。 Thanks 谢谢

The problem with drawRect is not the function call. drawRect的问题不是函数调用。 You can't just call drawRect, there is a lot of setup needed to set up the correct context for drawRect. 您不仅可以调用drawRect,还需要进行很多设置才能为drawRect设置正确的上下文。 And the code doing that setup can check that there is no drawRect method and avoid the whole setup, but it cannot detect that drawRect does nothing. 而且执行该设置的代码可以检查是否没有drawRect方法并避免整个设置,但是它无法检测到drawRect没有执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM