From 42aba3076dc9b6c4f8f35dd79cbf2992f7373d4f Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Fri, 19 Dec 2014 20:45:55 +0100 Subject: QQmlJS::Codegen: Short circuit in qmlErrors to avoid QUrl allocation costs. This takes the time taken in qmlErrors for my (admittedly terribly morbid) testcase from ~104ms to ~1ms. Change-Id: I288086caa6e6b58f67e9feb6f1761c3310f01ead Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4codegen.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index bb27d897a6..ba4c450aae 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2841,6 +2841,11 @@ QList Codegen::errors() const QList Codegen::qmlErrors() const { QList qmlErrors; + + // Short circuit to avoid costly (de)heap allocation of QUrl if there are no errors. + if (_errors.size() == 0) + return qmlErrors; + qmlErrors.reserve(_errors.size()); QUrl url(_fileNameIsUrl ? QUrl(_module->fileName) : QUrl::fromLocalFile(_module->fileName)); -- cgit v1.2.3