diff options
author | Svenn-Arne Dragly <svenn-arne.dragly@qt.io> | 2017-09-05 14:03:18 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-09-06 18:10:19 +0000 |
commit | 6000d6f561f284b57312c7a5274ec724aaac44e9 (patch) | |
tree | 8ea2575205f62f3339a774b2f232ce7ff2c5fadc /src | |
parent | d5926d26e2b39920acd1ecd22a33bc65c3cf49ad (diff) |
Improve performance of FilterKey comparison
Reduce the number of copies and make sure the types are compared first.
Change-Id: I6bdd411b6e16ef0f92a32de9733d737aab73835b
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/render/materialsystem/filterkey.cpp | 20 | ||||
-rw-r--r-- | src/render/materialsystem/filterkey_p.h | 4 |
2 files changed, 10 insertions, 14 deletions
diff --git a/src/render/materialsystem/filterkey.cpp b/src/render/materialsystem/filterkey.cpp index fd911c419..167413451 100644 --- a/src/render/materialsystem/filterkey.cpp +++ b/src/render/materialsystem/filterkey.cpp @@ -73,16 +73,6 @@ void FilterKey::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &ch m_value = data.value; } -QVariant FilterKey::value() const -{ - return m_value; -} - -QString FilterKey::name() const -{ - return m_name; -} - void FilterKey::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) { switch (e->type()) { @@ -106,8 +96,14 @@ bool FilterKey::operator ==(const FilterKey &other) { if (&other == this) return true; - return ((other.name() == name()) && - (other.value() == value())); + // TODO create a QVaraint::fastCompare function that returns false + // if types are not equal. For now, applying + // https://codereview.qt-project.org/#/c/204484/ + // and adding the following early comparison of the types should give + // an equivalent performance gain: + return (other.value().type() == value().type() && + other.name() == name() && + other.value() == value()); } bool FilterKey::operator !=(const FilterKey &other) diff --git a/src/render/materialsystem/filterkey_p.h b/src/render/materialsystem/filterkey_p.h index 4aea3d78a..6a098861c 100644 --- a/src/render/materialsystem/filterkey_p.h +++ b/src/render/materialsystem/filterkey_p.h @@ -69,8 +69,8 @@ public: ~FilterKey(); void cleanup(); - QVariant value() const; - QString name() const; + const QVariant &value() const { return m_value; } + const QString &name() const { return m_name; } void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; bool operator ==(const FilterKey &other); bool operator !=(const FilterKey &other); |