diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-09 09:21:19 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-11 12:56:22 +0200 |
| commit | 2260b46a7c92799eddf3f9b75f4ec170256dcb9c (patch) | |
| tree | 312cd20447da989ebc4ba0a6f9ff6b80079b8ec2 /src/qmlcompiler/qqmljsutils.cpp | |
| parent | 53ee2748ac05534dab895bab19449a3d5207900a (diff) | |
QQmlJSUtils: Pass non-trivial parameters as const ref
Coverity-Id: 392715
Change-Id: I5b38f070511965b1fd10cf286b7727acdb892fcb
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsutils.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljsutils.cpp | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/qmlcompiler/qqmljsutils.cpp b/src/qmlcompiler/qqmljsutils.cpp index ee153f1a85..9e506ca6bb 100644 --- a/src/qmlcompiler/qqmljsutils.cpp +++ b/src/qmlcompiler/qqmljsutils.cpp @@ -39,8 +39,9 @@ using namespace Qt::StringLiterals; origin, which is not an alias. */ QQmlJSUtils::ResolvedAlias -QQmlJSUtils::resolveAlias(const QQmlJSTypeResolver *typeResolver, QQmlJSMetaProperty property, - QQmlJSScope::ConstPtr owner, +QQmlJSUtils::resolveAlias(const QQmlJSTypeResolver *typeResolver, + const QQmlJSMetaProperty &property, + const QQmlJSScope::ConstPtr &owner, const QQmlJSUtils::AliasResolutionVisitor &visitor) { Q_ASSERT(property.isAlias()); @@ -49,43 +50,42 @@ QQmlJSUtils::resolveAlias(const QQmlJSTypeResolver *typeResolver, QQmlJSMetaProp ResolvedAlias result {}; result.owner = owner; - while (property.isAlias()) { - { - // this is special (seemingly useless) block which is necessary when - // we have an alias pointing to an alias. this way we avoid a check - // whether a property is an alias at the very end of the loop body - owner = result.owner; - result = ResolvedAlias {}; - } + for (QQmlJSMetaProperty nextProperty = property; nextProperty.isAlias();) { + + // this is a special (seemingly useless) section which is necessary when + // we have an alias pointing to an alias. this way we avoid a check + // whether a property is an alias at the very end of the loop body + QQmlJSScope::ConstPtr resultOwner = result.owner; + result = ResolvedAlias {}; + visitor.reset(); - auto aliasExprBits = property.aliasExpression().split(u'.'); + auto aliasExprBits = nextProperty.aliasExpression().split(u'.'); // resolve id first: - owner = typeResolver->scopeForId(aliasExprBits[0], owner); - if (!owner) + resultOwner = typeResolver->scopeForId(aliasExprBits[0], resultOwner); + if (!resultOwner) return {}; - visitor.processResolvedId(owner); + visitor.processResolvedId(resultOwner); aliasExprBits.removeFirst(); // Note: for simplicity, remove the <id> - result.owner = owner; + result.owner = resultOwner; result.kind = QQmlJSUtils::AliasTarget_Object; // reset the property to avoid endless loop when aliasExprBits is empty - property = QQmlJSMetaProperty {}; + nextProperty = QQmlJSMetaProperty {}; - for (qsizetype i = 0; i < aliasExprBits.size(); ++i) { - const QString &bit = qAsConst(aliasExprBits)[i]; - property = owner->property(bit); - if (!property.isValid()) + for (const QString &bit : qAsConst(aliasExprBits)) { + nextProperty = resultOwner->property(bit); + if (!nextProperty.isValid()) return {}; - visitor.processResolvedProperty(property, owner); + visitor.processResolvedProperty(nextProperty, resultOwner); - result.property = property; - result.owner = owner; + result.property = nextProperty; + result.owner = resultOwner; result.kind = QQmlJSUtils::AliasTarget_Property; - owner = property.type(); + resultOwner = nextProperty.type(); } } |
