[libcxx-commits] [libcxx] [libc++] Optimize vector<bool>::reserve (PR #170137)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 1 05:34:53 PST 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/170137

None

>From 8f0170c690f61fa9339aceed990ac84bd63dd283 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 1 Dec 2025 14:34:13 +0100
Subject: [PATCH] [libc++] Optimize vector<bool>::reserve

---
 libcxx/include/__vector/vector_bool.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index 6cb8f2a7fb012..5e2b3d4e92d47 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -856,7 +856,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type _
       this->__throw_length_error();
     vector __v(this->get_allocator());
     __v.__vallocate(__n);
-    __v.__construct_at_end(this->begin(), this->end(), this->size());
+    __v.__size_ = __size_;
+    std::copy_n(__begin_, __external_cap_to_internal(__size_), __v.__begin_);
     swap(__v);
   }
 }



More information about the libcxx-commits mailing list