ICU-23004 simpler U_FORCE_INLINE

This commit is contained in:
Markus Scherer 2025-03-24 11:11:46 -07:00
parent 5208745688
commit cb1de7ef66
2 changed files with 128 additions and 125 deletions

View file

@ -122,20 +122,23 @@
/**
* \def U_FORCE_INLINE
* Forces function inlining on compilers that are known to support it.
* Place this before specifiers like "static" and "explicit".
*
* This does not replace the "inline" keyword which suspends the One Definition Rule (ODR)
* in addition to optionally serving as an inlining hint to the compiler.
*
* @internal
*/
#ifdef U_FORCE_INLINE
// already defined
#elif defined(U_IN_DOXYGEN)
# define U_FORCE_INLINE(specifiers) specifiers inline
# define U_FORCE_INLINE
#elif (defined(__clang__) && __clang__) || U_GCC_MAJOR_MINOR != 0
# define U_FORCE_INLINE(specifiers) [[gnu::always_inline]] specifiers
# define U_FORCE_INLINE [[gnu::always_inline]]
#elif defined(U_REAL_MSVC)
# define U_FORCE_INLINE(specifiers) specifiers __forceinline
#elif defined(__ICC) || defined(__INTEL_COMPILER)
# define U_FORCE_INLINE(specifiers) specifiers __attribute__((always_inline))
# define U_FORCE_INLINE __forceinline
#else
# define U_FORCE_INLINE(specifiers) specifiers inline
# define U_FORCE_INLINE
#endif
// Before ICU 65, function-like, multi-statement ICU macros were just defined as

View file

@ -30,14 +30,14 @@ typedef int32_t UChar32;
constexpr UChar32 U_SENTINEL = -1;
#ifdef U_FORCE_INLINE
// already defined
#elif defined(U_IN_DOXYGEN)
# define U_FORCE_INLINE
#elif (defined(__clang__) && __clang__) || U_GCC_MAJOR_MINOR != 0
# define U_FORCE_INLINE(specifiers) [[gnu::always_inline]] specifiers
# define U_FORCE_INLINE [[gnu::always_inline]]
#elif defined(U_REAL_MSVC)
# define U_FORCE_INLINE(specifiers) specifiers __forceinline
#elif defined(__ICC) || defined(__INTEL_COMPILER)
# define U_FORCE_INLINE(specifiers) specifiers __attribute__((always_inline))
# define U_FORCE_INLINE __forceinline
#else
# define U_FORCE_INLINE(specifiers) specifiers inline
# define U_FORCE_INLINE
#endif
// unicode/uversion.h
#define U_HEADER_ONLY_NAMESPACE header
@ -332,14 +332,14 @@ class UTFImpl<
"For 8-bit strings, the SURROGATE option does not have an equivalent.");
public:
// Handle ill-formed UTF-8
U_FORCE_INLINE(static) CP32 sub() {
U_FORCE_INLINE static CP32 sub() {
switch (behavior) {
case UTF_BEHAVIOR_NEGATIVE: return U_SENTINEL;
case UTF_BEHAVIOR_FFFD: return 0xfffd;
}
}
U_FORCE_INLINE(static) void inc(UnitIter &p, const UnitIter &limit) {
U_FORCE_INLINE static void inc(UnitIter &p, const UnitIter &limit) {
// Very similar to U8_FWD_1().
uint8_t b = *p;
++p;
@ -364,7 +364,7 @@ public:
}
}
U_FORCE_INLINE(static) void dec(UnitIter start, UnitIter &p) {
U_FORCE_INLINE static void dec(UnitIter start, UnitIter &p) {
// Very similar to U8_BACK_1().
uint8_t c = *--p;
if (U8_IS_TRAIL(c) && p != start) {
@ -398,7 +398,7 @@ public:
}
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> readAndInc(UnitIter &p, UnitIter limit) {
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> readAndInc(UnitIter &p, UnitIter limit) {
// Very similar to U8_NEXT_OR_FFFD().
UnitIter p0 = p;
CP32 c = uint8_t(*p);
@ -433,7 +433,7 @@ public:
return {sub(), length, false, p0, p};
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> singlePassReadAndInc(
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> singlePassReadAndInc(
UnitIter &p, const UnitIter &limit) {
// Very similar to U8_NEXT_OR_FFFD().
CP32 c = uint8_t(*p);
@ -468,7 +468,7 @@ public:
return {sub(), length, false};
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> decAndRead(UnitIter start, UnitIter &p) {
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> decAndRead(UnitIter start, UnitIter &p) {
// Very similar to U8_PREV_OR_FFFD().
UnitIter p0 = p;
CP32 c = uint8_t(*--p);
@ -535,7 +535,7 @@ class UTFImpl<
static_assert(sizeof(CP32) == 4, "CP32 must be a 32-bit type to hold a code point");
public:
// Handle ill-formed UTF-16: One unpaired surrogate.
U_FORCE_INLINE(static) CP32 sub(CP32 surrogate) {
U_FORCE_INLINE static CP32 sub(CP32 surrogate) {
switch (behavior) {
case UTF_BEHAVIOR_NEGATIVE: return U_SENTINEL;
case UTF_BEHAVIOR_FFFD: return 0xfffd;
@ -543,7 +543,7 @@ public:
}
}
U_FORCE_INLINE(static) void inc(UnitIter &p, const UnitIter &limit) {
U_FORCE_INLINE static void inc(UnitIter &p, const UnitIter &limit) {
// Very similar to U16_FWD_1().
auto c = *p;
++p;
@ -552,7 +552,7 @@ public:
}
}
U_FORCE_INLINE(static) void dec(UnitIter start, UnitIter &p) {
U_FORCE_INLINE static void dec(UnitIter start, UnitIter &p) {
// Very similar to U16_BACK_1().
UnitIter p1;
if (U16_IS_TRAIL(*--p) && p != start && (p1 = p, U16_IS_LEAD(*--p1))) {
@ -560,7 +560,7 @@ public:
}
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> readAndInc(UnitIter &p, UnitIter limit) {
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> readAndInc(UnitIter &p, UnitIter limit) {
// Very similar to U16_NEXT_OR_FFFD().
UnitIter p0 = p;
CP32 c = *p;
@ -579,7 +579,7 @@ public:
}
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> singlePassReadAndInc(
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> singlePassReadAndInc(
UnitIter &p, const UnitIter &limit) {
// Very similar to U16_NEXT_OR_FFFD().
CP32 c = *p;
@ -598,7 +598,7 @@ public:
}
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> decAndRead(UnitIter start, UnitIter &p) {
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> decAndRead(UnitIter start, UnitIter &p) {
// Very similar to U16_PREV_OR_FFFD().
UnitIter p0 = p;
CP32 c = *--p;
@ -629,7 +629,7 @@ class UTFImpl<
static_assert(sizeof(CP32) == 4, "CP32 must be a 32-bit type to hold a code point");
public:
// Handle ill-formed UTF-32
U_FORCE_INLINE(static) CP32 sub(bool forSurrogate, CP32 surrogate) {
U_FORCE_INLINE static CP32 sub(bool forSurrogate, CP32 surrogate) {
switch (behavior) {
case UTF_BEHAVIOR_NEGATIVE: return U_SENTINEL;
case UTF_BEHAVIOR_FFFD: return 0xfffd;
@ -637,15 +637,15 @@ public:
}
}
U_FORCE_INLINE(static) void inc(UnitIter &p, const UnitIter &/*limit*/) {
U_FORCE_INLINE static void inc(UnitIter &p, const UnitIter &/*limit*/) {
++p;
}
U_FORCE_INLINE(static) void dec(UnitIter /*start*/, UnitIter &p) {
U_FORCE_INLINE static void dec(UnitIter /*start*/, UnitIter &p) {
--p;
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> readAndInc(UnitIter &p, UnitIter /*limit*/) {
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> readAndInc(UnitIter &p, UnitIter /*limit*/) {
UnitIter p0 = p;
uint32_t uc = *p;
CP32 c = uc;
@ -657,7 +657,7 @@ public:
}
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> singlePassReadAndInc(
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> singlePassReadAndInc(
UnitIter &p, const UnitIter &/*limit*/) {
uint32_t uc = *p;
CP32 c = uc;
@ -669,7 +669,7 @@ public:
}
}
U_FORCE_INLINE(static) CodeUnits<CP32, UnitIter> decAndRead(UnitIter /*start*/, UnitIter &p) {
U_FORCE_INLINE static CodeUnits<CP32, UnitIter> decAndRead(UnitIter /*start*/, UnitIter &p) {
UnitIter p0 = p;
uint32_t uc = *--p;
CP32 c = uc;
@ -695,18 +695,18 @@ class UnsafeUTFImpl<
sizeof(typename std::iterator_traits<UnitIter>::value_type) == 1>> {
static_assert(sizeof(CP32) == 4, "CP32 must be a 32-bit type to hold a code point");
public:
U_FORCE_INLINE(static) void inc(UnitIter &p) {
U_FORCE_INLINE static void inc(UnitIter &p) {
// Very similar to U8_FWD_1_UNSAFE().
uint8_t b = *p;
std::advance(p, 1 + U8_COUNT_TRAIL_BYTES_UNSAFE(b));
}
U_FORCE_INLINE(static) void dec(UnitIter &p) {
U_FORCE_INLINE static void dec(UnitIter &p) {
// Very similar to U8_BACK_1_UNSAFE().
while (U8_IS_TRAIL(*--p)) {}
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> readAndInc(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> readAndInc(UnitIter &p) {
// Very similar to U8_NEXT_UNSAFE().
UnitIter p0 = p;
CP32 c = uint8_t(*p);
@ -736,7 +736,7 @@ public:
}
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> singlePassReadAndInc(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> singlePassReadAndInc(UnitIter &p) {
// Very similar to U8_NEXT_UNSAFE().
CP32 c = uint8_t(*p);
++p;
@ -765,7 +765,7 @@ public:
}
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> decAndRead(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> decAndRead(UnitIter &p) {
// Very similar to U8_PREV_UNSAFE().
UnitIter p0 = p;
CP32 c = uint8_t(*--p);
@ -801,7 +801,7 @@ class UnsafeUTFImpl<
sizeof(typename std::iterator_traits<UnitIter>::value_type) == 2>> {
static_assert(sizeof(CP32) == 4, "CP32 must be a 32-bit type to hold a code point");
public:
U_FORCE_INLINE(static) void inc(UnitIter &p) {
U_FORCE_INLINE static void inc(UnitIter &p) {
// Very similar to U16_FWD_1_UNSAFE().
auto c = *p;
++p;
@ -810,14 +810,14 @@ public:
}
}
U_FORCE_INLINE(static) void dec(UnitIter &p) {
U_FORCE_INLINE static void dec(UnitIter &p) {
// Very similar to U16_BACK_1_UNSAFE().
if (U16_IS_TRAIL(*--p)) {
--p;
}
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> readAndInc(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> readAndInc(UnitIter &p) {
// Very similar to U16_NEXT_UNSAFE().
UnitIter p0 = p;
CP32 c = *p;
@ -832,7 +832,7 @@ public:
}
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> singlePassReadAndInc(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> singlePassReadAndInc(UnitIter &p) {
// Very similar to U16_NEXT_UNSAFE().
CP32 c = *p;
++p;
@ -846,7 +846,7 @@ public:
}
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> decAndRead(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> decAndRead(UnitIter &p) {
// Very similar to U16_PREV_UNSAFE().
UnitIter p0 = p;
CP32 c = *--p;
@ -869,28 +869,28 @@ class UnsafeUTFImpl<
sizeof(typename std::iterator_traits<UnitIter>::value_type) == 4>> {
static_assert(sizeof(CP32) == 4, "CP32 must be a 32-bit type to hold a code point");
public:
U_FORCE_INLINE(static) void inc(UnitIter &p) {
U_FORCE_INLINE static void inc(UnitIter &p) {
++p;
}
U_FORCE_INLINE(static) void dec(UnitIter &p) {
U_FORCE_INLINE static void dec(UnitIter &p) {
--p;
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> readAndInc(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> readAndInc(UnitIter &p) {
UnitIter p0 = p;
CP32 c = *p;
++p;
return {c, 1, p0, p};
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> singlePassReadAndInc(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> singlePassReadAndInc(UnitIter &p) {
CP32 c = *p;
++p;
return {c, 1};
}
U_FORCE_INLINE(static) UnsafeCodeUnits<CP32, UnitIter> decAndRead(UnitIter &p) {
U_FORCE_INLINE static UnsafeCodeUnits<CP32, UnitIter> decAndRead(UnitIter &p) {
UnitIter p0 = p;
CP32 c = *--p;
return {c, 1, p, p0};
@ -964,7 +964,7 @@ public:
* @param limit Limit (exclusive end) of the range
* @draft ICU 78
*/
U_FORCE_INLINE() UTFIterator(UnitIter start, UnitIter p, UnitIter limit) :
U_FORCE_INLINE UTFIterator(UnitIter start, UnitIter p, UnitIter limit) :
p_(p), start_(start), limit_(limit), units_(0, 0, false, p, p) {}
/**
* Constructor with start == p < limit.
@ -974,7 +974,7 @@ public:
* @param limit Limit (exclusive end) of the range
* @draft ICU 78
*/
U_FORCE_INLINE() UTFIterator(UnitIter p, UnitIter limit) :
U_FORCE_INLINE UTFIterator(UnitIter p, UnitIter limit) :
p_(p), start_(p), limit_(limit), units_(0, 0, false, p, p) {}
/**
* Constructs an iterator start or limit sentinel.
@ -984,24 +984,24 @@ public:
* @param p Range start or limit
* @draft ICU 78
*/
U_FORCE_INLINE(explicit) UTFIterator(UnitIter p) : p_(p), start_(p), limit_(p), units_(0, 0, false, p, p) {}
U_FORCE_INLINE explicit UTFIterator(UnitIter p) : p_(p), start_(p), limit_(p), units_(0, 0, false, p, p) {}
/** Move constructor. @draft ICU 78 */
U_FORCE_INLINE() UTFIterator(UTFIterator &&src) noexcept = default;
U_FORCE_INLINE UTFIterator(UTFIterator &&src) noexcept = default;
/** Move assignment operator. @draft ICU 78 */
U_FORCE_INLINE() UTFIterator &operator=(UTFIterator &&src) noexcept = default;
U_FORCE_INLINE UTFIterator &operator=(UTFIterator &&src) noexcept = default;
/** Copy constructor. @draft ICU 78 */
U_FORCE_INLINE() UTFIterator(const UTFIterator &other) = default;
U_FORCE_INLINE UTFIterator(const UTFIterator &other) = default;
/** Copy assignment operator. @draft ICU 78 */
U_FORCE_INLINE() UTFIterator &operator=(const UTFIterator &other) = default;
U_FORCE_INLINE UTFIterator &operator=(const UTFIterator &other) = default;
/**
* @param other Another iterator
* @return true if this operator is at the same position as the other one
* @draft ICU 78
*/
U_FORCE_INLINE() bool operator==(const UTFIterator &other) const {
U_FORCE_INLINE bool operator==(const UTFIterator &other) const {
return getLogicalPosition() == other.getLogicalPosition();
}
/**
@ -1009,7 +1009,7 @@ public:
* @return true if this operator is not at the same position as the other one
* @draft ICU 78
*/
U_FORCE_INLINE() bool operator!=(const UTFIterator &other) const { return !operator==(other); }
U_FORCE_INLINE bool operator!=(const UTFIterator &other) const { return !operator==(other); }
/**
* Decodes the code unit sequence at the current position.
@ -1017,7 +1017,7 @@ public:
* @return CodeUnits with the decoded code point etc.
* @draft ICU 78
*/
U_FORCE_INLINE() CodeUnits<CP32, UnitIter> operator*() const {
U_FORCE_INLINE CodeUnits<CP32, UnitIter> operator*() const {
if (state_ == 0) {
units_ = Impl::readAndInc(p_, limit_);
state_ = 1;
@ -1033,7 +1033,7 @@ public:
* an opaque proxy object so that <code>iter->codePoint()</code> etc. works.
* @draft ICU 78
*/
U_FORCE_INLINE() Proxy operator->() const {
U_FORCE_INLINE Proxy operator->() const {
if (state_ == 0) {
units_ = Impl::readAndInc(p_, limit_);
state_ = 1;
@ -1047,7 +1047,7 @@ public:
* @return this iterator
* @draft ICU 78
*/
U_FORCE_INLINE() UTFIterator &operator++() { // pre-increment
U_FORCE_INLINE UTFIterator &operator++() { // pre-increment
if (state_ > 0) {
// operator*() called readAndInc() so p_ is already ahead.
state_ = 0;
@ -1069,7 +1069,7 @@ public:
* returns an opaque proxy object so that <code>*iter++</code> still works.
* @draft ICU 78
*/
U_FORCE_INLINE() UTFIterator operator++(int) { // post-increment
U_FORCE_INLINE UTFIterator operator++(int) { // post-increment
if (state_ > 0) {
// operator*() called readAndInc() so p_ is already ahead.
UTFIterator result(*this);
@ -1098,7 +1098,7 @@ public:
* @draft ICU 78
*/
template<typename Iter = UnitIter>
U_FORCE_INLINE()
U_FORCE_INLINE
std::enable_if_t<
std::is_base_of_v<
std::bidirectional_iterator_tag,
@ -1122,7 +1122,7 @@ public:
* @draft ICU 78
*/
template<typename Iter = UnitIter>
U_FORCE_INLINE()
U_FORCE_INLINE
std::enable_if_t<
std::is_base_of_v<
std::bidirectional_iterator_tag,
@ -1137,7 +1137,7 @@ public:
private:
friend class std::reverse_iterator<UTFIterator<CP32, behavior, UnitIter>>;
U_FORCE_INLINE() UnitIter getLogicalPosition() const {
U_FORCE_INLINE UnitIter getLogicalPosition() const {
return state_ <= 0 ? p_ : units_.begin();
}
@ -1190,26 +1190,26 @@ public:
using difference_type = typename std::iterator_traits<UnitIter>::difference_type;
using iterator_category = std::input_iterator_tag;
U_FORCE_INLINE() UTFIterator(UnitIter p, UnitIter limit) : p_(std::move(p)), limit_(std::move(limit)) {}
U_FORCE_INLINE UTFIterator(UnitIter p, UnitIter limit) : p_(std::move(p)), limit_(std::move(limit)) {}
// Constructs an iterator start or limit sentinel.
// Requires p to be copyable.
U_FORCE_INLINE(explicit) UTFIterator(UnitIter p) : p_(std::move(p)), limit_(p_) {}
U_FORCE_INLINE explicit UTFIterator(UnitIter p) : p_(std::move(p)), limit_(p_) {}
U_FORCE_INLINE() UTFIterator(UTFIterator &&src) noexcept = default;
U_FORCE_INLINE() UTFIterator &operator=(UTFIterator &&src) noexcept = default;
U_FORCE_INLINE UTFIterator(UTFIterator &&src) noexcept = default;
U_FORCE_INLINE UTFIterator &operator=(UTFIterator &&src) noexcept = default;
U_FORCE_INLINE() UTFIterator(const UTFIterator &other) = default;
U_FORCE_INLINE() UTFIterator &operator=(const UTFIterator &other) = default;
U_FORCE_INLINE UTFIterator(const UTFIterator &other) = default;
U_FORCE_INLINE UTFIterator &operator=(const UTFIterator &other) = default;
U_FORCE_INLINE() bool operator==(const UTFIterator &other) const {
U_FORCE_INLINE bool operator==(const UTFIterator &other) const {
return p_ == other.p_ && ahead_ == other.ahead_;
// Strictly speaking, we should check if the logical position is the same.
// However, we cannot advance, or do arithmetic with, a single-pass UnitIter.
}
U_FORCE_INLINE() bool operator!=(const UTFIterator &other) const { return !operator==(other); }
U_FORCE_INLINE bool operator!=(const UTFIterator &other) const { return !operator==(other); }
U_FORCE_INLINE() CodeUnits<CP32, UnitIter> operator*() const {
U_FORCE_INLINE CodeUnits<CP32, UnitIter> operator*() const {
if (!ahead_) {
units_ = Impl::singlePassReadAndInc(p_, limit_);
ahead_ = true;
@ -1217,7 +1217,7 @@ public:
return units_;
}
U_FORCE_INLINE() Proxy operator->() const {
U_FORCE_INLINE Proxy operator->() const {
if (!ahead_) {
units_ = Impl::singlePassReadAndInc(p_, limit_);
ahead_ = true;
@ -1225,7 +1225,7 @@ public:
return Proxy(units_);
}
U_FORCE_INLINE() UTFIterator &operator++() { // pre-increment
U_FORCE_INLINE UTFIterator &operator++() { // pre-increment
if (ahead_) {
// operator*() called readAndInc() so p_ is already ahead.
ahead_ = false;
@ -1235,7 +1235,7 @@ public:
return *this;
}
U_FORCE_INLINE() Proxy operator++(int) { // post-increment
U_FORCE_INLINE Proxy operator++(int) { // post-increment
if (ahead_) {
// operator*() called readAndInc() so p_ is already ahead.
ahead_ = false;
@ -1292,22 +1292,22 @@ public:
using difference_type = typename std::iterator_traits<UnitIter>::difference_type;
using iterator_category = std::bidirectional_iterator_tag;
U_FORCE_INLINE(explicit) reverse_iterator(U_HEADER_ONLY_NAMESPACE::UTFIterator<CP32, behavior, UnitIter> iter) :
U_FORCE_INLINE explicit reverse_iterator(U_HEADER_ONLY_NAMESPACE::UTFIterator<CP32, behavior, UnitIter> iter) :
p_(iter.getLogicalPosition()), start_(iter.start_), limit_(iter.limit_),
units_(0, 0, false, p_, p_) {}
U_FORCE_INLINE() reverse_iterator(reverse_iterator &&src) noexcept = default;
U_FORCE_INLINE() reverse_iterator &operator=(reverse_iterator &&src) noexcept = default;
U_FORCE_INLINE reverse_iterator(reverse_iterator &&src) noexcept = default;
U_FORCE_INLINE reverse_iterator &operator=(reverse_iterator &&src) noexcept = default;
U_FORCE_INLINE() reverse_iterator(const reverse_iterator &other) = default;
U_FORCE_INLINE() reverse_iterator &operator=(const reverse_iterator &other) = default;
U_FORCE_INLINE reverse_iterator(const reverse_iterator &other) = default;
U_FORCE_INLINE reverse_iterator &operator=(const reverse_iterator &other) = default;
U_FORCE_INLINE() bool operator==(const reverse_iterator &other) const {
U_FORCE_INLINE bool operator==(const reverse_iterator &other) const {
return getLogicalPosition() == other.getLogicalPosition();
}
U_FORCE_INLINE() bool operator!=(const reverse_iterator &other) const { return !operator==(other); }
U_FORCE_INLINE bool operator!=(const reverse_iterator &other) const { return !operator==(other); }
U_FORCE_INLINE() CodeUnits_ operator*() const {
U_FORCE_INLINE CodeUnits_ operator*() const {
if (state_ == 0) {
units_ = Impl::decAndRead(start_, p_);
state_ = -1;
@ -1315,7 +1315,7 @@ public:
return units_;
}
U_FORCE_INLINE() Proxy operator->() const {
U_FORCE_INLINE Proxy operator->() const {
if (state_ == 0) {
units_ = Impl::decAndRead(start_, p_);
state_ = -1;
@ -1323,7 +1323,7 @@ public:
return Proxy(units_);
}
U_FORCE_INLINE() reverse_iterator &operator++() { // pre-increment
U_FORCE_INLINE reverse_iterator &operator++() { // pre-increment
if (state_ < 0) {
// operator*() called decAndRead() so p_ is already behind.
state_ = 0;
@ -1337,7 +1337,7 @@ public:
return *this;
}
U_FORCE_INLINE() reverse_iterator operator++(int) { // post-increment
U_FORCE_INLINE reverse_iterator operator++(int) { // post-increment
if (state_ < 0) {
// operator*() called decAndRead() so p_ is already behind.
reverse_iterator result(*this);
@ -1358,7 +1358,7 @@ public:
}
}
U_FORCE_INLINE() reverse_iterator &operator--() { // pre-decrement
U_FORCE_INLINE reverse_iterator &operator--() { // pre-decrement
if (state_ < 0) {
// operator*() called decAndRead() so p_ is behind the logical position.
p_ = units_.end();
@ -1368,14 +1368,14 @@ public:
return *this;
}
U_FORCE_INLINE() reverse_iterator operator--(int) { // post-decrement
U_FORCE_INLINE reverse_iterator operator--(int) { // post-decrement
reverse_iterator result(*this);
operator--();
return result;
}
private:
U_FORCE_INLINE() UnitIter getLogicalPosition() const {
U_FORCE_INLINE UnitIter getLogicalPosition() const {
return state_ >= 0 ? p_ : units_.end();
}
@ -1616,24 +1616,24 @@ public:
* @param p Initial position inside the range, or a range sentinel
* @draft ICU 78
*/
U_FORCE_INLINE(explicit) UnsafeUTFIterator(UnitIter p) : p_(p), units_(0, 0, p, p) {}
U_FORCE_INLINE explicit UnsafeUTFIterator(UnitIter p) : p_(p), units_(0, 0, p, p) {}
/** Move constructor. @draft ICU 78 */
U_FORCE_INLINE() UnsafeUTFIterator(UnsafeUTFIterator &&src) noexcept = default;
U_FORCE_INLINE UnsafeUTFIterator(UnsafeUTFIterator &&src) noexcept = default;
/** Move assignment operator. @draft ICU 78 */
U_FORCE_INLINE() UnsafeUTFIterator &operator=(UnsafeUTFIterator &&src) noexcept = default;
U_FORCE_INLINE UnsafeUTFIterator &operator=(UnsafeUTFIterator &&src) noexcept = default;
/** Copy constructor. @draft ICU 78 */
U_FORCE_INLINE() UnsafeUTFIterator(const UnsafeUTFIterator &other) = default;
U_FORCE_INLINE UnsafeUTFIterator(const UnsafeUTFIterator &other) = default;
/** Copy assignment operator. @draft ICU 78 */
U_FORCE_INLINE() UnsafeUTFIterator &operator=(const UnsafeUTFIterator &other) = default;
U_FORCE_INLINE UnsafeUTFIterator &operator=(const UnsafeUTFIterator &other) = default;
/**
* @param other Another iterator
* @return true if this operator is at the same position as the other one
* @draft ICU 78
*/
U_FORCE_INLINE() bool operator==(const UnsafeUTFIterator &other) const {
U_FORCE_INLINE bool operator==(const UnsafeUTFIterator &other) const {
return getLogicalPosition() == other.getLogicalPosition();
}
/**
@ -1641,7 +1641,7 @@ public:
* @return true if this operator is not at the same position as the other one
* @draft ICU 78
*/
U_FORCE_INLINE() bool operator!=(const UnsafeUTFIterator &other) const { return !operator==(other); }
U_FORCE_INLINE bool operator!=(const UnsafeUTFIterator &other) const { return !operator==(other); }
/**
* Decodes the code unit sequence at the current position.
@ -1649,7 +1649,7 @@ public:
* @return CodeUnits with the decoded code point etc.
* @draft ICU 78
*/
U_FORCE_INLINE() UnsafeCodeUnits<CP32, UnitIter> operator*() const {
U_FORCE_INLINE UnsafeCodeUnits<CP32, UnitIter> operator*() const {
if (state_ == 0) {
units_ = Impl::readAndInc(p_);
state_ = 1;
@ -1665,7 +1665,7 @@ public:
* an opaque proxy object so that <code>iter->codePoint()</code> etc. works.
* @draft ICU 78
*/
U_FORCE_INLINE() Proxy operator->() const {
U_FORCE_INLINE Proxy operator->() const {
if (state_ == 0) {
units_ = Impl::readAndInc(p_);
state_ = 1;
@ -1679,7 +1679,7 @@ public:
* @return this iterator
* @draft ICU 78
*/
U_FORCE_INLINE() UnsafeUTFIterator &operator++() { // pre-increment
U_FORCE_INLINE UnsafeUTFIterator &operator++() { // pre-increment
if (state_ > 0) {
// operator*() called readAndInc() so p_ is already ahead.
state_ = 0;
@ -1701,7 +1701,7 @@ public:
* returns an opaque proxy object so that <code>*iter++</code> still works.
* @draft ICU 78
*/
U_FORCE_INLINE() UnsafeUTFIterator operator++(int) { // post-increment
U_FORCE_INLINE UnsafeUTFIterator operator++(int) { // post-increment
if (state_ > 0) {
// operator*() called readAndInc() so p_ is already ahead.
UnsafeUTFIterator result(*this);
@ -1730,7 +1730,7 @@ public:
* @draft ICU 78
*/
template<typename Iter = UnitIter>
U_FORCE_INLINE()
U_FORCE_INLINE
std::enable_if_t<
std::is_base_of_v<
std::bidirectional_iterator_tag,
@ -1754,7 +1754,7 @@ public:
* @draft ICU 78
*/
template<typename Iter = UnitIter>
U_FORCE_INLINE()
U_FORCE_INLINE
std::enable_if_t<
std::is_base_of_v<
std::bidirectional_iterator_tag,
@ -1769,7 +1769,7 @@ public:
private:
friend class std::reverse_iterator<UnsafeUTFIterator<CP32, UnitIter>>;
U_FORCE_INLINE() UnitIter getLogicalPosition() const {
U_FORCE_INLINE UnitIter getLogicalPosition() const {
return state_ <= 0 ? p_ : units_.begin();
}
@ -1817,22 +1817,22 @@ public:
using difference_type = typename std::iterator_traits<UnitIter>::difference_type;
using iterator_category = std::input_iterator_tag;
U_FORCE_INLINE(explicit) UnsafeUTFIterator(UnitIter p) : p_(std::move(p)) {}
U_FORCE_INLINE explicit UnsafeUTFIterator(UnitIter p) : p_(std::move(p)) {}
U_FORCE_INLINE() UnsafeUTFIterator(UnsafeUTFIterator &&src) noexcept = default;
U_FORCE_INLINE() UnsafeUTFIterator &operator=(UnsafeUTFIterator &&src) noexcept = default;
U_FORCE_INLINE UnsafeUTFIterator(UnsafeUTFIterator &&src) noexcept = default;
U_FORCE_INLINE UnsafeUTFIterator &operator=(UnsafeUTFIterator &&src) noexcept = default;
U_FORCE_INLINE() UnsafeUTFIterator(const UnsafeUTFIterator &other) = default;
U_FORCE_INLINE() UnsafeUTFIterator &operator=(const UnsafeUTFIterator &other) = default;
U_FORCE_INLINE UnsafeUTFIterator(const UnsafeUTFIterator &other) = default;
U_FORCE_INLINE UnsafeUTFIterator &operator=(const UnsafeUTFIterator &other) = default;
U_FORCE_INLINE() bool operator==(const UnsafeUTFIterator &other) const {
U_FORCE_INLINE bool operator==(const UnsafeUTFIterator &other) const {
return p_ == other.p_ && ahead_ == other.ahead_;
// Strictly speaking, we should check if the logical position is the same.
// However, we cannot advance, or do arithmetic with, a single-pass UnitIter.
}
U_FORCE_INLINE() bool operator!=(const UnsafeUTFIterator &other) const { return !operator==(other); }
U_FORCE_INLINE bool operator!=(const UnsafeUTFIterator &other) const { return !operator==(other); }
U_FORCE_INLINE() UnsafeCodeUnits<CP32, UnitIter> operator*() const {
U_FORCE_INLINE UnsafeCodeUnits<CP32, UnitIter> operator*() const {
if (!ahead_) {
units_ = Impl::singlePassReadAndInc(p_);
ahead_ = true;
@ -1840,7 +1840,7 @@ public:
return units_;
}
U_FORCE_INLINE() Proxy operator->() const {
U_FORCE_INLINE Proxy operator->() const {
if (!ahead_) {
units_ = Impl::singlePassReadAndInc(p_);
ahead_ = true;
@ -1848,7 +1848,7 @@ public:
return Proxy(units_);
}
U_FORCE_INLINE() UnsafeUTFIterator &operator++() { // pre-increment
U_FORCE_INLINE UnsafeUTFIterator &operator++() { // pre-increment
if (ahead_) {
// operator*() called readAndInc() so p_ is already ahead.
ahead_ = false;
@ -1858,7 +1858,7 @@ public:
return *this;
}
U_FORCE_INLINE() Proxy operator++(int) { // post-increment
U_FORCE_INLINE Proxy operator++(int) { // post-increment
if (ahead_) {
// operator*() called readAndInc() so p_ is already ahead.
ahead_ = false;
@ -1912,21 +1912,21 @@ public:
using difference_type = typename std::iterator_traits<UnitIter>::difference_type;
using iterator_category = std::bidirectional_iterator_tag;
U_FORCE_INLINE(explicit) reverse_iterator(U_HEADER_ONLY_NAMESPACE::UnsafeUTFIterator<CP32, UnitIter> iter) :
U_FORCE_INLINE explicit reverse_iterator(U_HEADER_ONLY_NAMESPACE::UnsafeUTFIterator<CP32, UnitIter> iter) :
p_(iter.getLogicalPosition()), units_(0, 0, p_, p_) {}
U_FORCE_INLINE() reverse_iterator(reverse_iterator &&src) noexcept = default;
U_FORCE_INLINE() reverse_iterator &operator=(reverse_iterator &&src) noexcept = default;
U_FORCE_INLINE reverse_iterator(reverse_iterator &&src) noexcept = default;
U_FORCE_INLINE reverse_iterator &operator=(reverse_iterator &&src) noexcept = default;
U_FORCE_INLINE() reverse_iterator(const reverse_iterator &other) = default;
U_FORCE_INLINE() reverse_iterator &operator=(const reverse_iterator &other) = default;
U_FORCE_INLINE reverse_iterator(const reverse_iterator &other) = default;
U_FORCE_INLINE reverse_iterator &operator=(const reverse_iterator &other) = default;
U_FORCE_INLINE() bool operator==(const reverse_iterator &other) const {
U_FORCE_INLINE bool operator==(const reverse_iterator &other) const {
return getLogicalPosition() == other.getLogicalPosition();
}
U_FORCE_INLINE() bool operator!=(const reverse_iterator &other) const { return !operator==(other); }
U_FORCE_INLINE bool operator!=(const reverse_iterator &other) const { return !operator==(other); }
U_FORCE_INLINE() UnsafeCodeUnits_ operator*() const {
U_FORCE_INLINE UnsafeCodeUnits_ operator*() const {
if (state_ == 0) {
units_ = Impl::decAndRead(p_);
state_ = -1;
@ -1934,7 +1934,7 @@ public:
return units_;
}
U_FORCE_INLINE() Proxy operator->() const {
U_FORCE_INLINE Proxy operator->() const {
if (state_ == 0) {
units_ = Impl::decAndRead(p_);
state_ = -1;
@ -1942,7 +1942,7 @@ public:
return Proxy(units_);
}
U_FORCE_INLINE() reverse_iterator &operator++() { // pre-increment
U_FORCE_INLINE reverse_iterator &operator++() { // pre-increment
if (state_ < 0) {
// operator*() called decAndRead() so p_ is already behind.
state_ = 0;
@ -1956,7 +1956,7 @@ public:
return *this;
}
U_FORCE_INLINE() reverse_iterator operator++(int) { // post-increment
U_FORCE_INLINE reverse_iterator operator++(int) { // post-increment
if (state_ < 0) {
// operator*() called decAndRead() so p_ is already behind.
reverse_iterator result(*this);
@ -1977,7 +1977,7 @@ public:
}
}
U_FORCE_INLINE() reverse_iterator &operator--() { // pre-decrement
U_FORCE_INLINE reverse_iterator &operator--() { // pre-decrement
if (state_ < 0) {
// operator*() called decAndRead() so p_ is behind the logical position.
p_ = units_.end();
@ -1987,14 +1987,14 @@ public:
return *this;
}
U_FORCE_INLINE() reverse_iterator operator--(int) { // post-decrement
U_FORCE_INLINE reverse_iterator operator--(int) { // post-decrement
reverse_iterator result(*this);
operator--();
return result;
}
private:
U_FORCE_INLINE() UnitIter getLogicalPosition() const {
U_FORCE_INLINE UnitIter getLogicalPosition() const {
return state_ >= 0 ? p_ : units_.end();
}