Re:In C++, is empty() faster than comparing the size with zero?
by Someone on Thursday October 28, 2021 @05:14PM
(#29032090)
No, it is very generic. See https://kristerw.blogspot.com/2019/04/how-llvm-optimizes-geo..., https://blog.matthieud.me/2020/exploring-clang-llvm-optimiza... (discussed at https://news.ycombinator.com/item?id=28207207)
(I remember reading a page with more examples, but cannot find it)
Here's an example where (I think) the two functions are equivalent, so I'm a little disappointed it couldn't make the same optimisation on the second one. (At least it still optimised the tail call to a jump.)
https://godbolt.org/z/K9rMajsjK