[libcxx-commits] [libcxx] [libc++][ranges] optimize the performance of `ranges::starts_with` (PR #84570)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 25 12:31:25 PDT 2024
https://github.com/ldionne approved this pull request.
I finally caught up to this patch. I tend to like the patch. I think it applies an optimization that should almost always be a win, except in cases where `ranges::equal` is slower than `ranges::mismatch`, which boils down to whether `memcmp` is faster than our implementation of `mismatch`. If I misunderstood something, please let me know.
Assuming I'm on the same page as the other reviewers, I would say this: comparing whether two ranges are equal is definitely "a simpler operation" (conceptually at least) than finding the point at which they don't match. So I think it makes sense to assume that `ranges::equal` should always be at least as fast as `ranges::mismatch` (in the worst case, I guess we could even implement `ranges::equal` by calling `ranges::mismatch` and checking that the result is the last iterator).
I understand that some C libraries might provide extremely poor quality of implementation for some functions, however I think that should be a bug filed on them and I don't think we should start deciding how to optimize our code based on that.
I have a few comments and I'd like to know if @philnik777 is fine with what I said above, but I'd say this patch otherwise LGTM.
https://github.com/llvm/llvm-project/pull/84570
More information about the libcxx-commits
mailing list