forked from qt-creator/qt-creator
QmlDesigner: Refactor resolveBinding method to use QStringView
- Changed the parameter type from QString to QStringView for better performance. - Replaced QString element with QStringView element. - Optimized the loop to use QStringView and auto for elements. - Improved readability and efficiency by reducing repeated split operations. Change-Id: I38d303d4939f0c14f7cf3a15153a5f645a4cb9a3 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -49,7 +49,7 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModelNode resolveBinding(const QString &binding, ModelNode currentNode) const;
|
ModelNode resolveBinding(QStringView binding, ModelNode currentNode) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
using BindingProperties = QList<BindingProperty>;
|
using BindingProperties = QList<BindingProperty>;
|
||||||
|
@@ -68,12 +68,12 @@ const QString &BindingProperty::expression() const
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelNode BindingProperty::resolveBinding(const QString &binding, ModelNode currentNode) const
|
ModelNode BindingProperty::resolveBinding(QStringView binding, ModelNode currentNode) const
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
QString element = binding.split(QLatin1Char('.')).at(0);
|
auto elements = binding.split(QLatin1Char('.'));
|
||||||
while (!element.isEmpty())
|
QStringView element = elements.front();
|
||||||
{
|
while (!element.isEmpty()) {
|
||||||
if (currentNode.isValid()) {
|
if (currentNode.isValid()) {
|
||||||
if (element == QLatin1String("parent")) {
|
if (element == QLatin1String("parent")) {
|
||||||
if (currentNode.hasParentProperty())
|
if (currentNode.hasParentProperty())
|
||||||
@@ -90,10 +90,10 @@ ModelNode BindingProperty::resolveBinding(const QString &binding, ModelNode curr
|
|||||||
currentNode = ModelNode(privateModel()->nodeForId(element), model(), view());
|
currentNode = ModelNode(privateModel()->nodeForId(element), model(), view());
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
if (index < binding.split(QLatin1Char('.')).size())
|
if (std::cmp_less(index, elements.size()))
|
||||||
element = binding.split(QLatin1Char('.')).at(index);
|
element = elements[index];
|
||||||
else
|
else
|
||||||
element.clear();
|
element = {};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return ModelNode();
|
return ModelNode();
|
||||||
|
@@ -1606,12 +1606,12 @@ InternalNodePointer ModelPrivate::currentTimelineNode() const
|
|||||||
return m_currentTimelineNode;
|
return m_currentTimelineNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalNodePointer ModelPrivate::nodeForId(const QString &id) const
|
InternalNodePointer ModelPrivate::nodeForId(QStringView id) const
|
||||||
{
|
{
|
||||||
return m_idNodeHash.value(id);
|
return m_idNodeHash.value(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelPrivate::hasId(const QString &id) const
|
bool ModelPrivate::hasId(QStringView id) const
|
||||||
{
|
{
|
||||||
return m_idNodeHash.contains(id);
|
return m_idNodeHash.contains(id);
|
||||||
}
|
}
|
||||||
|
@@ -292,8 +292,8 @@ public:
|
|||||||
void setScriptFunctions(const InternalNodePointer &node, const QStringList &scriptFunctionList);
|
void setScriptFunctions(const InternalNodePointer &node, const QStringList &scriptFunctionList);
|
||||||
void setNodeSource(const InternalNodePointer &node, const QString &nodeSource);
|
void setNodeSource(const InternalNodePointer &node, const QString &nodeSource);
|
||||||
|
|
||||||
InternalNodePointer nodeForId(const QString &id) const;
|
InternalNodePointer nodeForId(QStringView id) const;
|
||||||
bool hasId(const QString &id) const;
|
bool hasId(QStringView id) const;
|
||||||
|
|
||||||
InternalNodePointer nodeForInternalId(qint32 internalId) const;
|
InternalNodePointer nodeForInternalId(qint32 internalId) const;
|
||||||
bool hasNodeForInternalId(qint32 internalId) const;
|
bool hasNodeForInternalId(qint32 internalId) const;
|
||||||
|
Reference in New Issue
Block a user