简体   繁体   English

如何在 Xcode 中为每个文件设置优化级别?

[英]How can I set optimization level per file in Xcode?

I'm writing some performance critical Swift code that I'm sure is safe to be optimized with -Ounchecked .我正在编写一些性能关键的 Swift 代码,我确信可以安全地使用-Ounchecked进行优化。 I'd like the rest of the code to be compiled with a less aggressive optimization.我希望以不那么激进的优化来编译其余的代码。

I can set compiler settings per file as per the answer here: Specific compiler flags for specific files in Xcode我可以根据这里的答案设置每个文件的编译器设置: Xcode 中特定文件的特定编译器标志

How can I use that knowledge to set a specific file in my project to one of Swift's various optimization levels?我如何使用这些知识将项目中的特定文件设置为 Swift 的各种优化级别之一? (ie what compiler settings are available to me and how can I use them) (即我可以使用哪些编译器设置以及如何使用它们)

I am not sure whether this is an answer to your question or just a side note but you can disable/enable optimization on specific function, not just per file, using optimize() compiler directive我不确定这是对您问题的回答还是只是一个旁注,但您可以使用 optimize() 编译器指令禁用/启用特定功能的优化,而不仅仅是每个文件

void* __attribute__((optimize("O0"))) myfuncn(void* pointer) {
    // unmodifiable compiler code
}

This will ensure your myfuncn() function will not be optimized这将确保您的 myfuncn() 函数不会被优化

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

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