Simplify qCompareThreeWay()

Use QtOrderingPrivate::reversed() in qCompareThreeWay() to avoid
conversions to Qt::partial_ordering and Qt::strong_ordering.

Task-number: QTBUG-119433
Pick-to: 6.7
Change-Id: Ia42bda518dcf23f5332cac9bb8d50baebef67e55
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
bb10
Ivan Solovev 2024-01-08 15:53:05 +01:00
parent 5d590a38d9
commit 0995358efa
1 changed files with 1 additions and 8 deletions

View File

@ -657,14 +657,7 @@ auto qCompareThreeWay(const LT &lhs, const RT &rhs)
return compareThreeWay(lhs, rhs);
} else {
const auto retval = compareThreeWay(rhs, lhs);
// We can compare any ordering type with Qt::partial_ordering, but we
// always need to return the right type. Use Qt::strong_ordering for
// casting, as it can be cast to any ordering type.
if (retval == Qt::partial_ordering::less)
return static_cast<decltype(retval)>(Qt::strong_ordering::greater);
else if (retval == Qt::partial_ordering::greater)
return static_cast<decltype(retval)>(Qt::strong_ordering::less);
return retval;
return QtOrderingPrivate::reversed(retval);
}
}