[libcxx-commits] [libcxx] [libc++] Remove unnecessary division and modulo operations in bitset (PR #121312)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 19 10:41:36 PDT 2025
https://github.com/winner245 updated https://github.com/llvm/llvm-project/pull/121312
>From 4e246700c31b95e48430bbcaa674faea48b1ba3c Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Sun, 29 Dec 2024 21:36:48 -0500
Subject: [PATCH 1/2] Remove unnecessary division and modulo operations in
bitset
---
libcxx/include/bitset | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index 669a3947a87af..f7c05a8de3da3 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -464,10 +464,10 @@ protected:
return __const_reference(&__first_, __storage_type(1) << __pos);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {
- return __iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
+ return __iterator(&__first_, __pos);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
- return __const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
+ return __const_iterator(&__first_, __pos);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
>From 7a4133f816efc53578cc6ed7fcb231fe71da6878 Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Wed, 19 Mar 2025 13:40:37 -0400
Subject: [PATCH 2/2] Add _LIBCPP_ASSERT_INTERNAL
---
libcxx/include/bitset | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index f7c05a8de3da3..30da9ab31833d 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -464,9 +464,11 @@ protected:
return __const_reference(&__first_, __storage_type(1) << __pos);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {
+ _LIBCPP_ASSERT_INTERNAL(__pos < __bits_per_word, "Out of bounds access in the single word bitset implementation.");
return __iterator(&__first_, __pos);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
+ _LIBCPP_ASSERT_INTERNAL(__pos < __bits_per_word, "Out of bounds access in the single word bitset implementation.");
return __const_iterator(&__first_, __pos);
}
More information about the libcxx-commits
mailing list