[libcxx-commits] [libcxx] [libc++] Remove redundant assignments in bitset string-like constructors (PR #121424)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 16 18:50:15 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Peng Liu (winner245)

<details>
<summary>Changes</summary>

The following three string-like constructors for `std::bitset` 
- `bitset(const CharT* str, std::size_t n, CharT zero, CharT one)`;
- `bitset(const std::basic_string<CharT, Traits, Alloc>& str, typename std::basic_string<CharT, Traits, Alloc>::size_type pos, CharT zero, CharT one)`;
- `bitset(std::basic_string_view<CharT, Traits> str, std::size_t pos, std::size_t n, CharT zero, CharT one)`

already initialize the underlying storage array to all zeroes via default-constructor of the base class `__bitset`. Therefore, re-assigning the storage array to zeroes via `std::fill_n` in the string-like constructors is truly redundant. 

---
Full diff: https://github.com/llvm/llvm-project/pull/121424.diff


1 Files Affected:

- (modified) libcxx/include/bitset (-1) 


``````````diff
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index a20842985b3d5..3cd4312e0171d 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -736,7 +736,6 @@ private:
       _CharT __c   = __str[__mp - 1 - __i];
       (*this)[__i] = _Traits::eq(__c, __one);
     }
-    std::fill(__base::__make_iter(__i), __base::__make_iter(_Size), false);
   }
 
   _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return __base::__hash_code(); }

``````````

</details>


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


More information about the libcxx-commits mailing list