logoalt Hacker News

dxxvi • today at 12:15 AM • 1 reply • view on HN

Is x = !x faster than x.toggle() because from my naked eyes no function is called? Or does the compiler know that the function toggle should be replace with `!=`? If the compiler does know that, how is that knowledge implemented? Is there a table of special functions that should be replaced with something else? Or some more clever way?


Replies

lern_too_spel • today at 12:24 AM

It has the #[inline] attribute.

https://std-dev-guide.rust-lang.org/policy/inline.html