[libcxx-commits] [libcxx] [libc++] fix minor performance issue in `basic_string<C>::append()` (PR #210078)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 21 05:15:23 PDT 2026
================
@@ -482,6 +483,41 @@ int main(int argc, char** argv) {
std::bind_front(bench_impl, std::integral_constant<size_t, large_size>{}, std::false_type{}));
}
+ {
+ static auto bench_impl =
+ []<size_t size, bool opaque, class CharT>(
+ std::integral_constant<size_t, size>,
+ std::bool_constant<opaque>,
+ std::type_identity<CharT>,
+ benchmark::State& state) {
+ std::basic_string<CharT> src(size, 'a');
+ auto getIterator = [&src](size_t i) {
+ // INT_MAX because we want overhead of ThrowingIterator without actually throwing
+ return ThrowingIterator<CharT>(src.data() + i, src.data() + src.size(), INT_MAX);
----------------
philnik777 wrote:
The compiler can simply remove the loop if it can prove that it has no side-effects, which is definitely the case for our `forward_iterator`, and even for more complicated ones like `map::iterator`: https://godbolt.org/z/4hdTnbsPd
https://github.com/llvm/llvm-project/pull/210078
More information about the libcxx-commits
mailing list