From b2cd5c805d153bdccd875884292edb118db87e4e Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 10 Jul 2023 07:58:53 +0200 Subject: QtQml: Optimize string/URL check in coerce() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We only need to check isString() once. This will also help static analyzers recognize that we cannot in fact dereference a nullptr there. Coverity-Id: 415866 Change-Id: I2f8462defbd9ffa7f4e0a8f184b920941a524eea Reviewed-by: Fabian Kosmale Reviewed-by: Olivier De Cannière --- src/qml/jsruntime/qv4jscall_p.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/qml/jsruntime/qv4jscall_p.h') diff --git a/src/qml/jsruntime/qv4jscall_p.h b/src/qml/jsruntime/qv4jscall_p.h index 7bb38a5fe9..c11a0be6f3 100644 --- a/src/qml/jsruntime/qv4jscall_p.h +++ b/src/qml/jsruntime/qv4jscall_p.h @@ -345,9 +345,9 @@ inline ReturnedValue coerce( : engine->newUrlObject()->asReturnedValue(); } // Since URL properties are stored as string, we need to support the string conversion here. - return value.isString() - ? engine->newUrlObject(QUrl(value.stringValue()->toQString()))->asReturnedValue() - : engine->newUrlObject()->asReturnedValue(); + if (const String *string = value.stringValue()) + return engine->newUrlObject(QUrl(string->toQString()))->asReturnedValue(); + return engine->newUrlObject()->asReturnedValue(); #if QT_CONFIG(regularexpression) case QMetaType::QRegularExpression: if (value.as()) -- cgit v1.2.3