mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Move ABSL_HARDENING_ASSERTs in constexpr methods to their own lines.
Prior to this change, some ABSL_HARDENING_ASSERTs were sequenced with the main work of some constexpr methods using the comma operator in order to satisfy C++11's constexpr requirements. However, putting the assertion and the main work of the function on the same line complicates measuring the performance impact of the assertions. As C++11 is no longer supported, this change moves the assertions to their own lines in order to make measuring their performance impact easier. PiperOrigin-RevId: 707614464 Change-Id: Idb621bb183b80db17e2db44c3ffc671b76bba92b
This commit is contained in:
committed by
Copybara-Service
parent
d6a75d96e6
commit
f0e59054ff
@@ -292,7 +292,8 @@ class ABSL_ATTRIBUTE_VIEW string_view {
|
||||
// Returns the ith element of the `string_view` using the array operator.
|
||||
// Note that this operator does not perform any bounds checking.
|
||||
constexpr const_reference operator[](size_type i) const {
|
||||
return ABSL_HARDENING_ASSERT(i < size()), ptr_[i];
|
||||
ABSL_HARDENING_ASSERT(i < size());
|
||||
return ptr_[i];
|
||||
}
|
||||
|
||||
// string_view::at()
|
||||
@@ -311,14 +312,16 @@ class ABSL_ATTRIBUTE_VIEW string_view {
|
||||
//
|
||||
// Returns the first element of a `string_view`.
|
||||
constexpr const_reference front() const {
|
||||
return ABSL_HARDENING_ASSERT(!empty()), ptr_[0];
|
||||
ABSL_HARDENING_ASSERT(!empty());
|
||||
return ptr_[0];
|
||||
}
|
||||
|
||||
// string_view::back()
|
||||
//
|
||||
// Returns the last element of a `string_view`.
|
||||
constexpr const_reference back() const {
|
||||
return ABSL_HARDENING_ASSERT(!empty()), ptr_[size() - 1];
|
||||
ABSL_HARDENING_ASSERT(!empty());
|
||||
return ptr_[size() - 1];
|
||||
}
|
||||
|
||||
// string_view::data()
|
||||
@@ -664,7 +667,8 @@ class ABSL_ATTRIBUTE_VIEW string_view {
|
||||
(std::numeric_limits<difference_type>::max)();
|
||||
|
||||
static constexpr size_type CheckLengthInternal(size_type len) {
|
||||
return ABSL_HARDENING_ASSERT(len <= kMaxSize), len;
|
||||
ABSL_HARDENING_ASSERT(len <= kMaxSize);
|
||||
return len;
|
||||
}
|
||||
|
||||
static constexpr size_type StrlenInternal(absl::Nonnull<const char*> str) {
|
||||
|
||||
@@ -429,14 +429,16 @@ class optional : private optional_internal::optional_data<T>,
|
||||
// Accesses the underlying `T` value of an `optional`. If the `optional` is
|
||||
// empty, behavior is undefined.
|
||||
constexpr const T& operator*() const& ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
||||
return ABSL_HARDENING_ASSERT(this->engaged_), reference();
|
||||
ABSL_HARDENING_ASSERT(this->engaged_);
|
||||
return reference();
|
||||
}
|
||||
T& operator*() & ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
||||
ABSL_HARDENING_ASSERT(this->engaged_);
|
||||
return reference();
|
||||
}
|
||||
constexpr const T&& operator*() const&& ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
||||
return ABSL_HARDENING_ASSERT(this->engaged_), std::move(reference());
|
||||
ABSL_HARDENING_ASSERT(this->engaged_);
|
||||
return std::move(reference());
|
||||
}
|
||||
T&& operator*() && ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
||||
ABSL_HARDENING_ASSERT(this->engaged_);
|
||||
|
||||
@@ -330,7 +330,8 @@ class ABSL_ATTRIBUTE_VIEW Span {
|
||||
//
|
||||
// Returns a reference to the i'th element of this span.
|
||||
constexpr reference operator[](size_type i) const noexcept {
|
||||
return ABSL_HARDENING_ASSERT(i < size()), ptr_[i];
|
||||
ABSL_HARDENING_ASSERT(i < size());
|
||||
return ptr_[i];
|
||||
}
|
||||
|
||||
// Span::at()
|
||||
@@ -349,7 +350,8 @@ class ABSL_ATTRIBUTE_VIEW Span {
|
||||
// Returns a reference to the first element of this span. The span must not
|
||||
// be empty.
|
||||
constexpr reference front() const noexcept {
|
||||
return ABSL_HARDENING_ASSERT(size() > 0), *data();
|
||||
ABSL_HARDENING_ASSERT(size() > 0);
|
||||
return *data();
|
||||
}
|
||||
|
||||
// Span::back()
|
||||
@@ -357,7 +359,8 @@ class ABSL_ATTRIBUTE_VIEW Span {
|
||||
// Returns a reference to the last element of this span. The span must not
|
||||
// be empty.
|
||||
constexpr reference back() const noexcept {
|
||||
return ABSL_HARDENING_ASSERT(size() > 0), *(data() + size() - 1);
|
||||
ABSL_HARDENING_ASSERT(size() > 0);
|
||||
return *(data() + size() - 1);
|
||||
}
|
||||
|
||||
// Span::begin()
|
||||
@@ -727,8 +730,8 @@ constexpr Span<T> MakeSpan(absl::Nullable<T*> ptr, size_t size) noexcept {
|
||||
|
||||
template <int&... ExplicitArgumentBarrier, typename T>
|
||||
Span<T> MakeSpan(absl::Nullable<T*> begin, absl::Nullable<T*> end) noexcept {
|
||||
return ABSL_HARDENING_ASSERT(begin <= end),
|
||||
Span<T>(begin, static_cast<size_t>(end - begin));
|
||||
ABSL_HARDENING_ASSERT(begin <= end);
|
||||
return Span<T>(begin, static_cast<size_t>(end - begin));
|
||||
}
|
||||
|
||||
template <int&... ExplicitArgumentBarrier, typename C>
|
||||
@@ -775,7 +778,8 @@ constexpr Span<const T> MakeConstSpan(absl::Nullable<T*> ptr,
|
||||
template <int&... ExplicitArgumentBarrier, typename T>
|
||||
Span<const T> MakeConstSpan(absl::Nullable<T*> begin,
|
||||
absl::Nullable<T*> end) noexcept {
|
||||
return ABSL_HARDENING_ASSERT(begin <= end), Span<const T>(begin, end - begin);
|
||||
ABSL_HARDENING_ASSERT(begin <= end);
|
||||
return Span<const T>(begin, end - begin);
|
||||
}
|
||||
|
||||
template <int&... ExplicitArgumentBarrier, typename C>
|
||||
|
||||
Reference in New Issue
Block a user