Commit f7be2f33 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[base] Inline AssertIteratorsInOrder in StringPiece

This change inlines the definition of AssertIteratorsInOrder into the
string_piece.h. While the goal of the previous implementation was to
avoid #including "base/logging.h", that header has already been included
with r353605, thus there should be no regressions when inlining this
definition. Having AssertIteratorsInOrder inline also directly supports
BasicStringPieces that are not base::StringPiece or base::StringPiece16.

Bug: 911896
Change-Id: I9150235dc79687b72f970872af950b0a82e1c0a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2019442
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735055}
parent 8defea3f
......@@ -438,16 +438,5 @@ StringPiece16 substr(const StringPiece16& self,
return substrT(self, pos, n);
}
#if DCHECK_IS_ON()
void AssertIteratorsInOrder(std::string::const_iterator begin,
std::string::const_iterator end) {
DCHECK(begin <= end) << "StringPiece iterators swapped or invalid.";
}
void AssertIteratorsInOrder(string16::const_iterator begin,
string16::const_iterator end) {
DCHECK(begin <= end) << "StringPiece iterators swapped or invalid.";
}
#endif
} // namespace internal
} // namespace base
......@@ -141,14 +141,6 @@ BASE_EXPORT StringPiece16 substr(const StringPiece16& self,
size_t pos,
size_t n);
#if DCHECK_IS_ON()
// Asserts that begin <= end to catch some errors with iterator usage.
BASE_EXPORT void AssertIteratorsInOrder(std::string::const_iterator begin,
std::string::const_iterator end);
BASE_EXPORT void AssertIteratorsInOrder(string16::const_iterator begin,
string16::const_iterator end);
#endif
} // namespace internal
// BasicStringPiece ------------------------------------------------------------
......@@ -189,11 +181,7 @@ template <typename STRING_TYPE> class BasicStringPiece {
: ptr_(offset), length_(len) {}
BasicStringPiece(const typename STRING_TYPE::const_iterator& begin,
const typename STRING_TYPE::const_iterator& end) {
#if DCHECK_IS_ON()
// This assertion is done out-of-line to avoid bringing in logging.h and
// instantiating logging macros for every instantiation.
internal::AssertIteratorsInOrder(begin, end);
#endif
DCHECK(begin <= end) << "StringPiece iterators swapped or invalid.";
length_ = static_cast<size_t>(std::distance(begin, end));
// The length test before assignment is to avoid dereferencing an iterator
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment