diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-07-18 15:22:16 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-07-20 11:15:56 +0000 |
commit | d4b7c81e9e77a38dd294e52f65ed5426b40f1396 (patch) | |
tree | e65d5909b75b311fb47c4dbea161bc4eadf10aad | |
parent | cb8ece3cbd118c8b49513af1457f5d84df4e99dd (diff) |
QCollator: Extract Method Private::ensureInitialized()
Avoids repetition of if (d->dirty) d->init() all over the place.
Pick-to: 6.4
Change-Id: Ifc819151b7c694e6cc1f48bbb837b37d108ca49a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r-- | src/corelib/text/qcollator.cpp | 6 | ||||
-rw-r--r-- | src/corelib/text/qcollator_icu.cpp | 7 | ||||
-rw-r--r-- | src/corelib/text/qcollator_macx.cpp | 8 | ||||
-rw-r--r-- | src/corelib/text/qcollator_p.h | 6 | ||||
-rw-r--r-- | src/corelib/text/qcollator_posix.cpp | 7 | ||||
-rw-r--r-- | src/corelib/text/qcollator_win.cpp | 7 |
6 files changed, 21 insertions, 20 deletions
diff --git a/src/corelib/text/qcollator.cpp b/src/corelib/text/qcollator.cpp index 990c68c062..fd00082cf7 100644 --- a/src/corelib/text/qcollator.cpp +++ b/src/corelib/text/qcollator.cpp @@ -97,8 +97,7 @@ QCollator::QCollator(const QCollator &other) { if (d) { // Ensure clean, lest both copies try to init() at the same time: - if (d->dirty) - d->init(); + d->ensureInitialized(); d->ref.ref(); } } @@ -123,8 +122,7 @@ QCollator &QCollator::operator=(const QCollator &other) d = other.d; if (d) { // Ensure clean, lest both copies try to init() at the same time: - if (d->dirty) - d->init(); + d->ensureInitialized(); d->ref.ref(); } } diff --git a/src/corelib/text/qcollator_icu.cpp b/src/corelib/text/qcollator_icu.cpp index fbc422c342..afd58b5d5e 100644 --- a/src/corelib/text/qcollator_icu.cpp +++ b/src/corelib/text/qcollator_icu.cpp @@ -78,8 +78,7 @@ int QCollator::compare(QStringView s1, QStringView s2) const if (!s2.size()) return +1; - if (d->dirty) - d->init(); + d->ensureInitialized(); if (d->collator) { return ucol_strcoll(d->collator, @@ -92,8 +91,8 @@ int QCollator::compare(QStringView s1, QStringView s2) const QCollatorSortKey QCollator::sortKey(const QString &string) const { - if (d->dirty) - d->init(); + d->ensureInitialized(); + if (d->isC()) return QCollatorSortKey(new QCollatorSortKeyPrivate(string.toUtf8())); diff --git a/src/corelib/text/qcollator_macx.cpp b/src/corelib/text/qcollator_macx.cpp index 9a57ef78fc..23c23bd53a 100644 --- a/src/corelib/text/qcollator_macx.cpp +++ b/src/corelib/text/qcollator_macx.cpp @@ -63,8 +63,8 @@ int QCollator::compare(QStringView s1, QStringView s2) const if (!s2.size()) return +1; - if (d->dirty) - d->init(); + d->ensureInitialized(); + if (!d->collator) return s1.compare(s2, caseSensitivity()); @@ -82,8 +82,8 @@ int QCollator::compare(QStringView s1, QStringView s2) const QCollatorSortKey QCollator::sortKey(const QString &string) const { - if (d->dirty) - d->init(); + d->ensureInitialized(); + if (!d->collator) { // What should (or even *can*) we do here ? (See init()'s comment.) qWarning("QCollator doesn't support sort keys for the C locale on Darwin"); diff --git a/src/corelib/text/qcollator_p.h b/src/corelib/text/qcollator_p.h index 6da153cdf0..b96cdbaa32 100644 --- a/src/corelib/text/qcollator_p.h +++ b/src/corelib/text/qcollator_p.h @@ -74,6 +74,12 @@ public: collator = NoCollator; } + void ensureInitialized() + { + if (dirty) + init(); + } + // Implemented by each back-end, in its own way: void init(); void cleanup(); diff --git a/src/corelib/text/qcollator_posix.cpp b/src/corelib/text/qcollator_posix.cpp index b409dbd96d..bddb748535 100644 --- a/src/corelib/text/qcollator_posix.cpp +++ b/src/corelib/text/qcollator_posix.cpp @@ -50,8 +50,8 @@ int QCollator::compare(QStringView s1, QStringView s2) const if (d->isC()) return s1.compare(s2, caseSensitivity()); - if (d->dirty) - d->init(); + + d->ensureInitialized(); QVarLengthArray<wchar_t> array1, array2; stringToWCharArray(array1, s1); @@ -61,8 +61,7 @@ int QCollator::compare(QStringView s1, QStringView s2) const QCollatorSortKey QCollator::sortKey(const QString &string) const { - if (d->dirty) - d->init(); + d->ensureInitialized(); QVarLengthArray<wchar_t> original; stringToWCharArray(original, string); diff --git a/src/corelib/text/qcollator_win.cpp b/src/corelib/text/qcollator_win.cpp index 45cf5488ad..405337924f 100644 --- a/src/corelib/text/qcollator_win.cpp +++ b/src/corelib/text/qcollator_win.cpp @@ -57,8 +57,7 @@ int QCollator::compare(QStringView s1, QStringView s2) const if (d->isC()) return s1.compare(s2, d->caseSensitivity); - if (d->dirty) - d->init(); + d->ensureInitialized(); //* from Windows documentation * // Returns one of the following values if successful. To maintain the C @@ -92,8 +91,8 @@ int QCollator::compare(QStringView s1, QStringView s2) const QCollatorSortKey QCollator::sortKey(const QString &string) const { - if (d->dirty) - d->init(); + d->ensureInitialized(); + if (d->isC()) return QCollatorSortKey(new QCollatorSortKeyPrivate(string)); |