简体   繁体   中英

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

func test() {}

Then a call to test() basically would not be called by the compiler.

Now if i remember correctly then Apple recommends against leaving an empty drawRect: method because it might hinder performance.

Now my question is if an empty function is never called by the compiler then why against the empty drawRect: I was just curious. Thanks

The problem with drawRect is not the function call. You can't just call drawRect, there is a lot of setup needed to set up the correct context for 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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