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>bb10
parent
cb8ece3cbd
commit
d4b7c81e9e
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue