[libcxx-commits] [PATCH] D131395: [libc++] Implement `lexicographical_compare_three_way`
Adrian Vogelsgesang via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 19 13:58:36 PDT 2022
avogelsgesang added inline comments.
================
Comment at: libcxx/include/__algorithm/lexicographical_compare_three_way.h:45-47
+ ptrdiff_t __len1 = __last1 - __first1;
+ ptrdiff_t __len2 = __last2 - __first2;
+ ptrdiff_t __min_len = std::min(__len1, __len2);
----------------
philnik wrote:
> (Thanks to @Quuxplusone for pointing it out!) Using `ptrdiff_t` is actually a bug because it might be smaller than the largest signed integer. Probably the easiest thing to do is to use `auto` instead and replace the `std::min()` with a ternary. For `__i` you could maybe use `decltype(__min_len)`. There might be a better way to do all this, I'm not sure.
Added a benchmark now. It shows a 30% improvement with the fast path
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131395/new/
https://reviews.llvm.org/D131395
More information about the libcxx-commits
mailing list