Rust 编译器对 `loop` 和 `while true` 做了哪些优化?
What optimizations does the Rust compiler make with `loop` versus `while true`?
除了它可以推断 loop
主体中设置的未初始化值这一事实之外,还有其他令人信服的理由 loop
存在吗?
除了你表明你的意图,没有什么区别。一旦在编译器中进行规范化,所有循环都是相同的。
看到 example of a loop
in the Rust playground and the same example with a while true
。生成的程序集完全相同。编译器警告 while true
-example 改用 loop
。
除了它可以推断 loop
主体中设置的未初始化值这一事实之外,还有其他令人信服的理由 loop
存在吗?
除了你表明你的意图,没有什么区别。一旦在编译器中进行规范化,所有循环都是相同的。
看到 example of a loop
in the Rust playground and the same example with a while true
。生成的程序集完全相同。编译器警告 while true
-example 改用 loop
。