Skip to content

Commit 642a502

Browse files
committed
Remove unnecessary cast
1 parent d4b9d9e commit 642a502

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

libcxx/include/__bit_reference

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,23 @@ struct __size_difference_type_traits<_Cp, __void_t<typename _Cp::difference_type
6868
// cast back to the unsigned `_StorageType`.
6969

7070
// Creates a mask of type `_StorageType` with a specified number of leading zeros (__clz) and sets all remaining
71-
// bits to one
71+
// bits to one.
7272
template <class _StorageType>
7373
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __trailing_mask(unsigned __clz) {
7474
static_assert(is_unsigned<_StorageType>::value, "__trailing_mask only works with unsigned types");
75-
return static_cast<_StorageType>(static_cast<_StorageType>(~static_cast<_StorageType>(0)) >> __clz);
75+
return _StorageType(~_StorageType(0)) >> __clz;
7676
}
7777

7878
// Creates a mask of type `_StorageType` with a specified number of leading zeros (__clz), a specified number of
79-
// trailing zeros (__ctz), and sets all bits in between to one
79+
// trailing zeros (__ctz), and sets all bits in between to one.
8080
template <class _StorageType>
8181
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __middle_mask(unsigned __clz, unsigned __ctz) {
8282
static_assert(is_unsigned<_StorageType>::value, "__middle_mask only works with unsigned types");
83-
return static_cast<_StorageType>(
84-
static_cast<_StorageType>(static_cast<_StorageType>(~static_cast<_StorageType>(0)) << __ctz) &
85-
std::__trailing_mask<_StorageType>(__clz));
83+
return _StorageType(_StorageType(~_StorageType(0)) << __ctz) & std::__trailing_mask<_StorageType>(__clz);
8684
}
8785

8886
// This function is designed to operate correctly even for smaller integral types like `uint8_t`, `uint16_t`,
89-
// or `unsigned short`. Casting back to _StorageType is crucial to prevent undefined behavior that can arise
90-
// from integral promotions.
87+
// or `unsigned short`.
9188
// See https://github.com/llvm/llvm-project/pull/122410.
9289
template <class _StoragePointer>
9390
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
@@ -97,8 +94,7 @@ __fill_masked_range(_StoragePointer __word, unsigned __clz, unsigned __ctz, bool
9794
using _StorageType = typename pointer_traits<_StoragePointer>::element_type;
9895
_LIBCPP_ASSERT_VALID_INPUT_RANGE(
9996
__ctz + __clz < sizeof(_StorageType) * CHAR_BIT, "__fill_masked_range called with invalid range");
100-
_StorageType __m = static_cast<_StorageType>(static_cast<_StorageType>(~static_cast<_StorageType>(0)) >> __clz) &
101-
static_cast<_StorageType>(static_cast<_StorageType>(~static_cast<_StorageType>(0)) << __ctz);
97+
_StorageType __m = std::__middle_mask<_StorageType>(__clz, __ctz);
10298
if (__fill_val)
10399
*__word |= __m;
104100
else

0 commit comments

Comments
 (0)