[libcxx-commits] [libcxx] [libc++] Speed up vector<bool> copy/move-ctors [1/3] (PR #120132)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 20 14:47:49 PST 2025


================
@@ -674,25 +676,30 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const alloca
 
 #endif // _LIBCPP_CXX03_LANG
 
+// This function copies each storage word as a whole, which is substantially more efficient than copying
----------------
winner245 wrote:

We do have 4 tests (`copy.pass.cpp`, `move.pass.cpp`, `copy_alloc.pass.cpp`, `move_alloc.pass.cpp`) covering for these constructors but the tests are limited to <= 3 bytes, which is less than the word size of 8 bytes. However, the optimizations for `std::{copy, fill_n}` have code branches covering 3 cases: 
- less than 1 word (this is the case currently covered);
- 2+ words, which contains at least one whole word (currently not covered);
- 3+ words, which contains whole words as well as partial word at the end (currently not covered).

 IMO, we should improve the tests for these constructors to cover more words. 

https://github.com/llvm/llvm-project/pull/120132


More information about the libcxx-commits mailing list