Skip to content

Commit f31e5f6

Browse files
committed
QRM: optimize headerData implementation using applyIndexSwitch helper
Instead of creating an array with all meta types, use applyIndexSwitch to make only the one QMetaType we need. Pick-to: 6.10 Change-Id: I7513b2936bc8448c555efe387e3fc33ebfc002e6 Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
1 parent b7bbd2a commit f31e5f6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/corelib/itemmodels/qrangemodel_impl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,6 @@ class QRangeModelImplBase : public QtPrivate::QQuasiVirtualInterface<QRangeModel
851851

852852
// Get the QMetaType for a tuple-element at a runtime index.
853853
// Used in the headerData implementation.
854-
template <typename Tuple, std::size_t ...I>
855-
static constexpr std::array<QMetaType, sizeof...(I)> makeMetaTypes(std::index_sequence<I...>)
856-
{
857-
return {{QMetaType::fromType<q20::remove_cvref_t<std::tuple_element_t<I, Tuple>>>()...}};
858-
}
859854
template <typename T>
860855
static constexpr QMetaType meta_type_at(size_t idx)
861856
{
@@ -866,7 +861,12 @@ class QRangeModelImplBase : public QtPrivate::QQuasiVirtualInterface<QRangeModel
866861
} else {
867862
constexpr auto size = std::tuple_size_v<type>;
868863
Q_ASSERT(idx < size);
869-
return makeMetaTypes<type>(std::make_index_sequence<size>{}).at(idx);
864+
QMetaType metaType;
865+
QtPrivate::applyIndexSwitch<size>(idx, [&metaType](auto idxConstant) {
866+
using ElementType = std::tuple_element_t<idxConstant.value, type>;
867+
metaType = QMetaType::fromType<q20::remove_cvref_t<ElementType>>();
868+
});
869+
return metaType;
870870
}
871871
}
872872

0 commit comments

Comments
 (0)