llvm-project
38595fb2 - [libc++] Remove a few unnecessary branches from basic_string::find (#137266)

Commit
148 days ago
[libc++] Remove a few unnecessary branches from basic_string::find (#137266) I've recently looked at the assembly for `basic_string::find()` and realized that there were a few branches I didn't expect. It turns out that we check for null before calling `__constexpr_memchr` in some cases, which the compiler doesn't optimize away. This is a really uncommon case though, so I'm not convinced it makes a ton of sense to optimize for that. The second case is where `__pos >= __sz`. There, we can instead check `__pos > __sz`, which the optimizer is able to remove if `__pos == 0`, which is also a quite common case (basic_string::find(CharT), without an explicit size parameter).
Author
Parents
Loading