diff options
author | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2016-04-20 13:39:58 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-05-10 08:17:00 +0000 |
commit | c6c0d730b7a88fa22f40d597183e91b73d9d165d (patch) | |
tree | 721fe747e03d5157f53a72992e71e33c2d1e72f9 /tests | |
parent | b697f511ab226079c161ea68c18ac85c5533d3cc (diff) |
QML: Remove internal field padding from QQuickAnchorPrivate.
Don't store QQuickAnchorLine, but store both fields separately in
QQuickAnchorPrivate. This prevents padding of QQuickAnchorLine, saving
48 bytes on x86_64 (or any platform where structs are 8-byte aligned).
On x86_64, this also removes ~180 instructions for each QQuickAnchor
creation/removal, and speeds up the constructor by 25%.
While in the neighborhood, do a drive-by change and merge
QQuickAnchorLine::AnchorLine and QQuickAnchors::Anchor by removing the
former.
Change-Id: I50ab6252b1903f5f1a075174e6185c3048a8f8ec
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickanchors/tst_qquickanchors.cpp | 33 | ||||
-rw-r--r-- | tests/auto/quick/qquickstates/tst_qquickstates.cpp | 4 | ||||
-rw-r--r-- | tests/benchmarks/qml/creation/tst_creation.cpp | 15 |
3 files changed, 32 insertions, 20 deletions
diff --git a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp index ab111a6cd3..77fa1292c4 100644 --- a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp +++ b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp @@ -39,7 +39,6 @@ #include "../shared/visualtestutil.h" Q_DECLARE_METATYPE(QQuickAnchors::Anchor) -Q_DECLARE_METATYPE(QQuickAnchorLine::AnchorLine) using namespace QQuickVisualTestUtil; @@ -351,14 +350,13 @@ void tst_qquickanchors::illegalSets_data() void tst_qquickanchors::reset() { QFETCH(QString, side); - QFETCH(QQuickAnchorLine::AnchorLine, anchorLine); - QFETCH(QQuickAnchors::Anchor, usedAnchor); + QFETCH(QQuickAnchors::Anchor, anchor); QQuickItem *baseItem = new QQuickItem; - QQuickAnchorLine anchor; - anchor.item = baseItem; - anchor.anchorLine = anchorLine; + QQuickAnchorLine anchorLine; + anchorLine.item = baseItem; + anchorLine.anchorLine = anchor; QQuickItem *item = new QQuickItem; QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); @@ -366,11 +364,11 @@ void tst_qquickanchors::reset() const QMetaObject *meta = itemPrivate->anchors()->metaObject(); QMetaProperty p = meta->property(meta->indexOfProperty(side.toUtf8().constData())); - QVERIFY(p.write(itemPrivate->anchors(), qVariantFromValue(anchor))); - QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(usedAnchor), true); + QVERIFY(p.write(itemPrivate->anchors(), qVariantFromValue(anchorLine))); + QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(anchor), true); QVERIFY(p.reset(itemPrivate->anchors())); - QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(usedAnchor), false); + QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(anchor), false); delete item; delete baseItem; @@ -379,17 +377,16 @@ void tst_qquickanchors::reset() void tst_qquickanchors::reset_data() { QTest::addColumn<QString>("side"); - QTest::addColumn<QQuickAnchorLine::AnchorLine>("anchorLine"); - QTest::addColumn<QQuickAnchors::Anchor>("usedAnchor"); + QTest::addColumn<QQuickAnchors::Anchor>("anchor"); - QTest::newRow("left") << "left" << QQuickAnchorLine::Left << QQuickAnchors::LeftAnchor; - QTest::newRow("top") << "top" << QQuickAnchorLine::Top << QQuickAnchors::TopAnchor; - QTest::newRow("right") << "right" << QQuickAnchorLine::Right << QQuickAnchors::RightAnchor; - QTest::newRow("bottom") << "bottom" << QQuickAnchorLine::Bottom << QQuickAnchors::BottomAnchor; + QTest::newRow("left") << "left" << QQuickAnchors::LeftAnchor; + QTest::newRow("top") << "top" << QQuickAnchors::TopAnchor; + QTest::newRow("right") << "right" << QQuickAnchors::RightAnchor; + QTest::newRow("bottom") << "bottom" << QQuickAnchors::BottomAnchor; - QTest::newRow("hcenter") << "horizontalCenter" << QQuickAnchorLine::HCenter << QQuickAnchors::HCenterAnchor; - QTest::newRow("vcenter") << "verticalCenter" << QQuickAnchorLine::VCenter << QQuickAnchors::VCenterAnchor; - QTest::newRow("baseline") << "baseline" << QQuickAnchorLine::Baseline << QQuickAnchors::BaselineAnchor; + QTest::newRow("hcenter") << "horizontalCenter" << QQuickAnchors::HCenterAnchor; + QTest::newRow("vcenter") << "verticalCenter" << QQuickAnchors::VCenterAnchor; + QTest::newRow("baseline") << "baseline" << QQuickAnchors::BaselineAnchor; } void tst_qquickanchors::resetConvenience() diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index 562d53bceb..9b152b0676 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -698,7 +698,7 @@ void tst_qquickstates::anchorChanges() rectPrivate->setState("right"); QCOMPARE(innerRect->x(), qreal(150)); QCOMPARE(aChanges->object(), qobject_cast<QQuickItem*>(innerRect)); - QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QQuickAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all) + QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QQuickAnchors::InvalidAnchor); //### was reset (how do we distinguish from not set at all) QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->right().item, rectPrivate->right().item); QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->right().anchorLine, rectPrivate->right().anchorLine); @@ -891,7 +891,7 @@ void tst_qquickstates::anchorChangesRTL() rectPrivate->setState("right"); QCOMPARE(innerRect->x(), offsetRTL(rect, innerRect) - qreal(150)); QCOMPARE(aChanges->object(), qobject_cast<QQuickItem*>(innerRect)); - QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QQuickAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all) + QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QQuickAnchors::InvalidAnchor); //### was reset (how do we distinguish from not set at all) QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->right().item, rectPrivate->right().item); QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->right().anchorLine, rectPrivate->right().anchorLine); diff --git a/tests/benchmarks/qml/creation/tst_creation.cpp b/tests/benchmarks/qml/creation/tst_creation.cpp index e126cdae7e..7b00eabc28 100644 --- a/tests/benchmarks/qml/creation/tst_creation.cpp +++ b/tests/benchmarks/qml/creation/tst_creation.cpp @@ -68,6 +68,7 @@ private slots: void itemtests_qml_data(); void itemtests_qml(); + void anchors_creation(); void anchors_heightChange(); private: @@ -375,6 +376,20 @@ void tst_creation::itemtests_qml() QBENCHMARK { delete component.create(); } } +void tst_creation::anchors_creation() +{ + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0\nItem { Item { anchors.bottom: parent.bottom } }", QUrl()); + + QObject *obj = component.create(); + delete obj; + + QBENCHMARK { + QObject *obj = component.create(); + delete obj; + } +} + void tst_creation::anchors_heightChange() { QQmlComponent component(&engine); |