aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2013-04-12 09:43:06 +0200
committerChristian Kandeler <christian.kandeler@digia.com>2013-04-12 15:10:46 +0200
commit6c64c84c7fd22f82d4ed423d57889a65e72097b8 (patch)
treeddd050777c8053546e7a73087991c118dacd1ca6
parent88fdf28c0d499f6dea6193072e796c313e61c2b3 (diff)
Help compiler with branch prediction.
Mark error checks in potentially performance-sensitive contexts with Q_UNLIKELY. Actual benefits unknown, but it cannot hurt. Change-Id: If3d2375965e6342b5d7a0b46ad2c8a41fd3567d0 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r--src/lib/buildgraph/command.cpp4
-rw-r--r--src/lib/buildgraph/cycledetector.cpp2
-rw-r--r--src/lib/buildgraph/processcommandexecutor.cpp2
-rw-r--r--src/lib/buildgraph/projectbuilddata.cpp6
-rw-r--r--src/lib/buildgraph/rulesapplicator.cpp8
-rw-r--r--src/lib/buildgraph/rulesevaluationcontext.cpp2
-rw-r--r--src/lib/buildgraph/transformer.cpp4
-rw-r--r--src/lib/jsextensions/file.cpp10
-rw-r--r--src/lib/jsextensions/moduleproperties.cpp6
-rw-r--r--src/lib/jsextensions/textfile.cpp2
-rw-r--r--src/lib/language/evaluatorscriptclass.cpp2
-rw-r--r--src/lib/language/importversion.cpp4
-rw-r--r--src/lib/language/itemreader.cpp6
-rw-r--r--src/lib/language/itemreaderastvisitor.cpp38
-rw-r--r--src/lib/language/language.cpp6
-rw-r--r--src/lib/language/moduleloader.cpp22
-rw-r--r--src/lib/language/projectresolver.cpp26
-rw-r--r--src/lib/language/scriptengine.cpp4
-rw-r--r--src/lib/tools/persistence.cpp2
-rw-r--r--src/lib/tools/profile.cpp2
-rw-r--r--src/lib/tools/qbsassert.h4
21 files changed, 81 insertions, 81 deletions
diff --git a/src/lib/buildgraph/command.cpp b/src/lib/buildgraph/command.cpp
index 64b4c57e3..c1e28319a 100644
--- a/src/lib/buildgraph/command.cpp
+++ b/src/lib/buildgraph/command.cpp
@@ -95,7 +95,7 @@ static QScriptValue js_CommandBase(QScriptContext *context, QScriptEngine *engin
static QScriptValue js_Command(QScriptContext *context, QScriptEngine *engine)
{
- if (context->argumentCount() != 2) {
+ if (Q_UNLIKELY(context->argumentCount() != 2)) {
return context->throwError(QScriptContext::SyntaxError,
"Command c'tor expects 2 arguments");
}
@@ -213,7 +213,7 @@ void ProcessCommand::store(QDataStream &s)
static QScriptValue js_JavaScriptCommand(QScriptContext *context, QScriptEngine *engine)
{
- if (context->argumentCount() != 0) {
+ if (Q_UNLIKELY(context->argumentCount() != 0)) {
return context->throwError(QScriptContext::SyntaxError,
"JavaScriptCommand c'tor doesn't take arguments.");
}
diff --git a/src/lib/buildgraph/cycledetector.cpp b/src/lib/buildgraph/cycledetector.cpp
index 1e9dcdb9d..3e39b70c9 100644
--- a/src/lib/buildgraph/cycledetector.cpp
+++ b/src/lib/buildgraph/cycledetector.cpp
@@ -53,7 +53,7 @@ void CycleDetector::visitProject(const ResolvedProjectConstPtr &project)
void CycleDetector::visitArtifact(Artifact *artifact)
{
- if (m_artifactsInCurrentPath.contains(artifact)) {
+ if (Q_UNLIKELY(m_artifactsInCurrentPath.contains(artifact))) {
Error error(Tr::tr("Cycle in build graph detected."));
foreach (const Artifact * const a, cycle(artifact))
error.append(a->filePath());
diff --git a/src/lib/buildgraph/processcommandexecutor.cpp b/src/lib/buildgraph/processcommandexecutor.cpp
index 501b97b03..533feda26 100644
--- a/src/lib/buildgraph/processcommandexecutor.cpp
+++ b/src/lib/buildgraph/processcommandexecutor.cpp
@@ -255,7 +255,7 @@ void ProcessCommandExecutor::onProcessFinished(int exitCode)
const bool errorOccurred = exitCode > processCommand()->maxExitCode();
sendProcessOutput(!errorOccurred);
- if (errorOccurred) {
+ if (Q_UNLIKELY(errorOccurred)) {
emit error(Error(Tr::tr("Process failed with exit code %1.").arg(exitCode)));
return;
}
diff --git a/src/lib/buildgraph/projectbuilddata.cpp b/src/lib/buildgraph/projectbuilddata.cpp
index d3bd7b510..3bd8843b4 100644
--- a/src/lib/buildgraph/projectbuilddata.cpp
+++ b/src/lib/buildgraph/projectbuilddata.cpp
@@ -283,7 +283,7 @@ void BuildDataResolver::resolveProductBuildData(const ResolvedProductPtr &produc
ArtifactsPerFileTagMap artifactsPerFileTag;
foreach (ResolvedProductPtr dependency, product->dependencies) {
- if (!dependency->enabled) {
+ if (Q_UNLIKELY(!dependency->enabled)) {
QString msg = Tr::tr("Product '%1' depends on '%2' but '%2' is disabled.");
throw Error(msg.arg(product->name, dependency->name));
}
@@ -318,7 +318,7 @@ void BuildDataResolver::resolveProductBuildData(const ResolvedProductPtr &produc
ArtifactList inputArtifacts;
foreach (const QString &inputFileName, rtrafo->inputs) {
Artifact *artifact = lookupArtifact(product, inputFileName);
- if (!artifact)
+ if (Q_UNLIKELY(!artifact))
throw Error(QString("Can't find artifact '%0' in the list of source files.").arg(inputFileName));
inputArtifacts += artifact;
}
@@ -353,7 +353,7 @@ void BuildDataResolver::resolveProductBuildData(const ResolvedProductPtr &produc
transformer->setupInputs(engine(), scope());
transformer->setupOutputs(engine(), scope());
transformer->createCommands(rtrafo->transform, evalContext());
- if (transformer->commands.isEmpty())
+ if (Q_UNLIKELY(transformer->commands.isEmpty()))
throw Error(QString("There's a transformer without commands."), rtrafo->transform->location);
}
diff --git a/src/lib/buildgraph/rulesapplicator.cpp b/src/lib/buildgraph/rulesapplicator.cpp
index 16e9a8d5a..a9781d10e 100644
--- a/src/lib/buildgraph/rulesapplicator.cpp
+++ b/src/lib/buildgraph/rulesapplicator.cpp
@@ -171,7 +171,7 @@ void RulesApplicator::doApply(const ArtifactList &inputArtifacts)
for (int i=0; i < ra->bindings.count(); ++i) {
const RuleArtifact::Binding &binding = ra->bindings.at(i);
scriptValue = engine()->evaluate(binding.code);
- if (scriptValue.isError()) {
+ if (Q_UNLIKELY(scriptValue.isError())) {
QString msg = QLatin1String("evaluating rule binding '%1': %2");
throw Error(msg.arg(binding.name.join(QLatin1String(".")), scriptValue.toString()), binding.location);
}
@@ -184,7 +184,7 @@ void RulesApplicator::doApply(const ArtifactList &inputArtifacts)
m_transformer->setupOutputs(engine(), scope());
m_transformer->createCommands(m_rule->script, evalContext());
- if (m_transformer->commands.isEmpty())
+ if (Q_UNLIKELY(m_transformer->commands.isEmpty()))
throw Error(QString("There's a rule without commands: %1.").arg(m_rule->toString()), m_rule->script->location);
}
@@ -220,7 +220,7 @@ Artifact *RulesApplicator::createOutputArtifact(const RuleArtifactConstPtr &rule
const ArtifactList &inputArtifacts)
{
QScriptValue scriptValue = engine()->evaluate(ruleArtifact->fileName);
- if (scriptValue.isError() || engine()->hasUncaughtException())
+ if (Q_UNLIKELY(scriptValue.isError() || engine()->hasUncaughtException()))
throw Error("Error in Rule.Artifact fileName: " + scriptValue.toString());
QString outputPath = scriptValue.toString();
outputPath.replace("..", "dotdot"); // don't let the output artifact "escape" its build dir
@@ -238,7 +238,7 @@ Artifact *RulesApplicator::createOutputArtifact(const RuleArtifactConstPtr &rule
m_transformer = outputArtifact->transformer;
m_transformer->inputs.unite(inputArtifacts);
- if (m_transformer->inputs.count() > 1 && !m_rule->multiplex) {
+ if (Q_UNLIKELY(m_transformer->inputs.count() > 1 && !m_rule->multiplex)) {
QString th = "[" + outputArtifact->fileTags.toStringList().join(", ") + "]";
QString e = Tr::tr("Conflicting rules for producing %1 %2 \n").arg(outputArtifact->filePath(), th);
th = "[" + m_rule->inputs.toStringList().join(", ")
diff --git a/src/lib/buildgraph/rulesevaluationcontext.cpp b/src/lib/buildgraph/rulesevaluationcontext.cpp
index b4d7a139d..28a58b4be 100644
--- a/src/lib/buildgraph/rulesevaluationcontext.cpp
+++ b/src/lib/buildgraph/rulesevaluationcontext.cpp
@@ -71,7 +71,7 @@ void RulesEvaluationContext::incrementProgressValue()
void RulesEvaluationContext::checkForCancelation()
{
- if (m_observer && m_observer->canceled())
+ if (Q_UNLIKELY(m_observer && m_observer->canceled()))
throw Error(Tr::tr("Build canceled."));
}
diff --git a/src/lib/buildgraph/transformer.cpp b/src/lib/buildgraph/transformer.cpp
index 646b0330f..4382637ac 100644
--- a/src/lib/buildgraph/transformer.cpp
+++ b/src/lib/buildgraph/transformer.cpp
@@ -137,14 +137,14 @@ void Transformer::createCommands(const PrepareScriptConstPtr &script,
ScriptEngine * const engine = evalContext->engine();
if (!script->scriptFunction.isValid() || script->scriptFunction.engine() != engine) {
script->scriptFunction = engine->evaluate(script->script);
- if (!script->scriptFunction.isFunction())
+ if (Q_UNLIKELY(!script->scriptFunction.isFunction()))
throw Error(Tr::tr("Invalid prepare script."), script->location);
}
engine->clearProperties();
QScriptValue scriptValue = script->scriptFunction.call();
modulePropertiesUsedInPrepareScript = engine->properties();
- if (engine->hasUncaughtException())
+ if (Q_UNLIKELY(engine->hasUncaughtException()))
throw Error("evaluating prepare script: " + engine->uncaughtException().toString(),
CodeLocation(script->location.fileName,
script->location.line + engine->uncaughtExceptionLineNumber() - 1));
diff --git a/src/lib/jsextensions/file.cpp b/src/lib/jsextensions/file.cpp
index c7dfd653b..c234fcee4 100644
--- a/src/lib/jsextensions/file.cpp
+++ b/src/lib/jsextensions/file.cpp
@@ -59,7 +59,7 @@ QScriptValue File::js_ctor(QScriptContext *context, QScriptEngine *engine)
QScriptValue File::js_copy(QScriptContext *context, QScriptEngine *engine)
{
Q_UNUSED(engine);
- if (context->argumentCount() < 2) {
+ if (Q_UNLIKELY(context->argumentCount() < 2)) {
return context->throwError(QScriptContext::SyntaxError,
Tr::tr("copy expects 2 arguments"));
}
@@ -67,7 +67,7 @@ QScriptValue File::js_copy(QScriptContext *context, QScriptEngine *engine)
const QString sourceFile = context->argument(0).toString();
const QString targetFile = context->argument(1).toString();
QString errorMessage;
- if (!copyFileRecursion(sourceFile, targetFile, &errorMessage))
+ if (Q_UNLIKELY(!copyFileRecursion(sourceFile, targetFile, &errorMessage)))
return context->throwError(errorMessage);
return true;
}
@@ -75,7 +75,7 @@ QScriptValue File::js_copy(QScriptContext *context, QScriptEngine *engine)
QScriptValue File::js_exists(QScriptContext *context, QScriptEngine *engine)
{
Q_UNUSED(engine);
- if (context->argumentCount() < 1) {
+ if (Q_UNLIKELY(context->argumentCount() < 1)) {
return context->throwError(QScriptContext::SyntaxError,
Tr::tr("exist expects 1 argument"));
}
@@ -85,14 +85,14 @@ QScriptValue File::js_exists(QScriptContext *context, QScriptEngine *engine)
QScriptValue File::js_remove(QScriptContext *context, QScriptEngine *engine)
{
Q_UNUSED(engine);
- if (context->argumentCount() < 1) {
+ if (Q_UNLIKELY(context->argumentCount() < 1)) {
return context->throwError(QScriptContext::SyntaxError,
Tr::tr("remove expects 1 argument"));
}
QString fileName = context->argument(0).toString();
QString errorMessage;
- if (!removeFileRecursion(QFileInfo(fileName), &errorMessage))
+ if (Q_UNLIKELY(!removeFileRecursion(QFileInfo(fileName), &errorMessage)))
return context->throwError(errorMessage);
return true;
}
diff --git a/src/lib/jsextensions/moduleproperties.cpp b/src/lib/jsextensions/moduleproperties.cpp
index a8fcf57fd..58bc6091f 100644
--- a/src/lib/jsextensions/moduleproperties.cpp
+++ b/src/lib/jsextensions/moduleproperties.cpp
@@ -81,19 +81,19 @@ QScriptValue ModuleProperties::js_moduleProperty(QScriptContext *context, QScrip
QScriptValue ModuleProperties::moduleProperties(QScriptContext *context, QScriptEngine *engine,
bool oneValue)
{
- if (context->argumentCount() < 2) {
+ if (Q_UNLIKELY(context->argumentCount() < 2)) {
return context->throwError(QScriptContext::SyntaxError,
Tr::tr("Function moduleProperties() expects 2 arguments"));
}
const QScriptValue objectWithProperties = context->thisObject();
const QScriptValue typeScriptValue = objectWithProperties.property(typeKey());
- if (!typeScriptValue.isString()) {
+ if (Q_UNLIKELY(!typeScriptValue.isString())) {
return context->throwError(QScriptContext::TypeError,
QLatin1String("Internal error: __type not set up"));
}
const QScriptValue ptrScriptValue = objectWithProperties.property(ptrKey());
- if (!ptrScriptValue.isNumber()) {
+ if (Q_UNLIKELY(!ptrScriptValue.isNumber())) {
return context->throwError(QScriptContext::TypeError,
QLatin1String("Internal error: __internalPtr not set up"));
}
diff --git a/src/lib/jsextensions/textfile.cpp b/src/lib/jsextensions/textfile.cpp
index 73f96fc4a..ea42b55b9 100644
--- a/src/lib/jsextensions/textfile.cpp
+++ b/src/lib/jsextensions/textfile.cpp
@@ -98,7 +98,7 @@ TextFile::TextFile(QScriptContext *context, const QString &file, OpenMode mode,
} else if (mode == WriteOnly) {
m = QIODevice::WriteOnly;
}
- if (!t->qfile->open(m)) {
+ if (Q_UNLIKELY(!t->qfile->open(m))) {
delete t->qfile;
t->qfile = 0;
context->throwError(QString::fromLatin1("unable to open '%1'")
diff --git a/src/lib/language/evaluatorscriptclass.cpp b/src/lib/language/evaluatorscriptclass.cpp
index 0f16e3991..16a206f40 100644
--- a/src/lib/language/evaluatorscriptclass.cpp
+++ b/src/lib/language/evaluatorscriptclass.cpp
@@ -356,7 +356,7 @@ QScriptValue EvaluatorScriptClass::scriptValueForBuiltin(BuiltinValue::Builtin b
QScriptValue EvaluatorScriptClass::js_getenv(QScriptContext *context, QScriptEngine *engine)
{
- if (context->argumentCount() < 1) {
+ if (Q_UNLIKELY(context->argumentCount() < 1)) {
return context->throwError(QScriptContext::SyntaxError,
QLatin1String("getenv expects 1 argument"));
}
diff --git a/src/lib/language/importversion.cpp b/src/lib/language/importversion.cpp
index 070ab7561..754359600 100644
--- a/src/lib/language/importversion.cpp
+++ b/src/lib/language/importversion.cpp
@@ -43,7 +43,7 @@ ImportVersion::ImportVersion()
ImportVersion ImportVersion::fromString(const QString &str, const CodeLocation &location)
{
QStringList lst = str.split(QLatin1Char('.'));
- if (lst.count() < 1 || lst.count() > 2)
+ if (Q_UNLIKELY(lst.count() < 1 || lst.count() > 2))
throw Error(Tr::tr("Wrong number of components in import version."), location);
ImportVersion v;
int *parts[] = {&v.m_major, &v.m_minor, 0};
@@ -52,7 +52,7 @@ ImportVersion ImportVersion::fromString(const QString &str, const CodeLocation &
break;
bool ok;
*parts[i] = lst.at(i).toInt(&ok);
- if (!ok)
+ if (Q_UNLIKELY(!ok))
throw Error(Tr::tr("Cannot parse import version."), location);
}
return v;
diff --git a/src/lib/language/itemreader.cpp b/src/lib/language/itemreader.cpp
index 27c63da0b..1c662d149 100644
--- a/src/lib/language/itemreader.cpp
+++ b/src/lib/language/itemreader.cpp
@@ -118,11 +118,11 @@ ItemReaderResult ItemReader::internalReadFile(const QString &filePath)
{
ASTCacheValue &cacheValue = (*m_astCache)[filePath];
if (cacheValue.isValid()) {
- if (cacheValue.isProcessing())
+ if (Q_UNLIKELY(cacheValue.isProcessing()))
throw Error(Tr::tr("Loop detected when importing '%1'.").arg(filePath));
} else {
QFile file(filePath);
- if (!file.open(QFile::ReadOnly))
+ if (Q_UNLIKELY(!file.open(QFile::ReadOnly)))
throw Error(Tr::tr("Couldn't open '%1'.").arg(filePath));
const QString code = QTextStream(&file).readAll();
@@ -133,7 +133,7 @@ ItemReaderResult ItemReader::internalReadFile(const QString &filePath)
file.close();
if (!parser.parse()) {
QList<QbsQmlJS::DiagnosticMessage> parserMessages = parser.diagnosticMessages();
- if (!parserMessages.isEmpty()) {
+ if (Q_UNLIKELY(!parserMessages.isEmpty())) {
Error err;
foreach (const QbsQmlJS::DiagnosticMessage &msg, parserMessages)
err.append(msg.message, toCodeLocation(filePath, msg.loc));
diff --git a/src/lib/language/itemreaderastvisitor.cpp b/src/lib/language/itemreaderastvisitor.cpp
index b7d7a8eb4..5c6ba26b0 100644
--- a/src/lib/language/itemreaderastvisitor.cpp
+++ b/src/lib/language/itemreaderastvisitor.cpp
@@ -67,7 +67,7 @@ bool ItemReaderASTVisitor::visit(AST::UiProgram *ast)
m_file = FileContext::create();
m_file->m_filePath = m_filePath;
- if (!ast->members->member)
+ if (Q_UNLIKELY(!ast->members->member))
throw Error(Tr::tr("No root item found in %1.").arg(m_filePath));
return true;
@@ -129,18 +129,18 @@ bool ItemReaderASTVisitor::visit(AST::UiImportList *uiImportList)
QString as;
if (isBase) {
- if (!import->importId.isNull()) {
+ if (Q_UNLIKELY(!import->importId.isNull())) {
throw Error(Tr::tr("Import of qbs.base must have no 'as <Name>'"),
toCodeLocation(import->importIdToken));
}
} else {
- if (import->importId.isNull()) {
+ if (Q_UNLIKELY(import->importId.isNull())) {
throw Error(Tr::tr("Imports require 'as <Name>'"),
toCodeLocation(import->importToken));
}
as = import->importId.toString();
- if (importAsNames.contains(as)) {
+ if (Q_UNLIKELY(importAsNames.contains(as))) {
throw Error(Tr::tr("Can't import into the same name more than once."),
toCodeLocation(import->importIdToken));
}
@@ -151,7 +151,7 @@ bool ItemReaderASTVisitor::visit(AST::UiImportList *uiImportList)
QString name = FileInfo::resolvePath(path, import->fileName.toString());
QFileInfo fi(name);
- if (!fi.exists())
+ if (Q_UNLIKELY(!fi.exists()))
throw Error(Tr::tr("Can't find imported file %0.").arg(name),
CodeLocation(m_filePath, import->fileNameToken.startLine,
import->fileNameToken.startColumn));
@@ -198,7 +198,7 @@ bool ItemReaderASTVisitor::visit(AST::UiImportList *uiImportList)
break;
}
}
- if (!found) {
+ if (Q_UNLIKELY(!found)) {
throw Error(Tr::tr("import %1 not found").arg(importUri.join(".")),
toCodeLocation(import->fileNameToken));
}
@@ -275,7 +275,7 @@ bool ItemReaderASTVisitor::visit(AST::UiObjectDefinition *ast)
static void checkDuplicateBinding(const ItemPtr &item, const QStringList &bindingName,
const AST::SourceLocation &sourceLocation)
{
- if (item->properties().contains(bindingName.last())) {
+ if (Q_UNLIKELY(item->properties().contains(bindingName.last()))) {
QString msg = Tr::tr("Duplicate binding for '%1'");
throw Error(msg.arg(bindingName.join(".")),
toCodeLocation(item->file()->filePath(), sourceLocation));
@@ -285,17 +285,17 @@ static void checkDuplicateBinding(const ItemPtr &item, const QStringList &bindin
bool ItemReaderASTVisitor::visit(AST::UiPublicMember *ast)
{
PropertyDeclaration p;
- if (ast->name.isEmpty())
+ if (Q_UNLIKELY(ast->name.isEmpty()))
throw Error(Tr::tr("public member without name"));
- if (ast->memberType.isEmpty())
+ if (Q_UNLIKELY(ast->memberType.isEmpty()))
throw Error(Tr::tr("public member without type"));
- if (ast->type == AST::UiPublicMember::Signal)
+ if (Q_UNLIKELY(ast->type == AST::UiPublicMember::Signal))
throw Error(Tr::tr("public member with signal type not supported"));
p.name = ast->name.toString();
p.type = PropertyDeclaration::propertyTypeFromString(ast->memberType.toString());
if (ast->typeModifier.compare(QLatin1String("list")))
p.flags |= PropertyDeclaration::ListProperty;
- else if (!ast->typeModifier.isEmpty())
+ else if (Q_UNLIKELY(!ast->typeModifier.isEmpty()))
throw Error(Tr::tr("public member with type modifier '%1' not supported").arg(
ast->typeModifier.toString()));
@@ -325,11 +325,11 @@ bool ItemReaderASTVisitor::visit(AST::UiScriptBinding *ast)
if (bindingName.length() == 1 && bindingName.first() == QLatin1String("id")) {
AST::ExpressionStatement *expStmt =
AST::cast<AST::ExpressionStatement *>(ast->statement);
- if (!expStmt)
+ if (Q_UNLIKELY(!expStmt))
throw Error(Tr::tr("id: must be followed by identifier"));
AST::IdentifierExpression *idExp =
AST::cast<AST::IdentifierExpression *>(expStmt->expression);
- if (!idExp || idExp->name.isEmpty())
+ if (Q_UNLIKELY(!idExp || idExp->name.isEmpty()))
throw Error(Tr::tr("id: must be followed by identifier"));
m_item->m_id = idExp->name.toString();
ensureIdScope(m_file);
@@ -352,7 +352,7 @@ bool ItemReaderASTVisitor::visit(AST::UiScriptBinding *ast)
bool ItemReaderASTVisitor::visit(AST::FunctionDeclaration *ast)
{
FunctionDeclaration f;
- if (ast->name.isNull())
+ if (Q_UNLIKELY(ast->name.isNull()))
throw Error(Tr::tr("function decl without name"));
f.setName(ast->name.toString());
@@ -408,7 +408,7 @@ ItemPtr ItemReaderASTVisitor::targetItemForBinding(const ItemPtr &item,
v = ItemValue::create(newItem);
targetItem->m_properties.insert(bindingName.at(i), v);
}
- if (v->type() != Value::ItemValueType) {
+ if (Q_UNLIKELY(v->type() != Value::ItemValueType)) {
QString msg = Tr::tr("Binding to non-item property.");
throw Error(msg, bindingLocation);
}
@@ -425,7 +425,7 @@ void ItemReaderASTVisitor::checkImportVersion(const AST::SourceLocation &version
const QString importVersionString = m_sourceCode.mid(versionToken.offset, versionToken.length);
const ImportVersion importVersion
= ImportVersion::fromString(importVersionString, toCodeLocation(versionToken));
- if (importVersion != m_languageVersion)
+ if (Q_UNLIKELY(importVersion != m_languageVersion))
throw Error(Tr::tr("Incompatible qbs version %1. This is qbs %2.").arg(
importVersionString, m_reader->builtins()->languageVersion()),
toCodeLocation(versionToken));
@@ -553,7 +553,7 @@ private:
it.value().staticCast<ItemValue>()->item());
} else if (it.value()->type() == Value::JSSourceValueType) {
ValuePtr aval = a->property(it.key());
- if (aval && aval->type() != Value::JSSourceValueType)
+ if (Q_UNLIKELY(aval && aval->type() != Value::JSSourceValueType))
throw Error(Tr::tr("Incompatible value type in unconditional value at %1.").arg(
aval->location().toString()));
apply(it.key(), a, aval.staticCast<JSSourceValue>(),
@@ -583,10 +583,10 @@ private:
void ItemReaderASTVisitor::handlePropertiesBlock(const ItemPtr &item, const ItemConstPtr &block)
{
ValuePtr value = block->property(QLatin1String("condition"));
- if (!value)
+ if (Q_UNLIKELY(!value))
throw Error(Tr::tr("Properties.condition must be provided."),
block->location());
- if (value->type() != Value::JSSourceValueType)
+ if (Q_UNLIKELY(value->type() != Value::JSSourceValueType))
throw Error(Tr::tr("Properties.condition must be a value binding."),
block->location());
JSSourceValuePtr srcval = value.staticCast<JSSourceValue>();
diff --git a/src/lib/language/language.cpp b/src/lib/language/language.cpp
index 08db12ec3..0efb8c1fd 100644
--- a/src/lib/language/language.cpp
+++ b/src/lib/language/language.cpp
@@ -414,7 +414,7 @@ QList<const ResolvedModule*> topSortModules(const QHash<const ResolvedModule*, Q
static QScriptValue js_getenv(QScriptContext *context, QScriptEngine *engine)
{
- if (context->argumentCount() < 1)
+ if (Q_UNLIKELY(context->argumentCount() < 1))
return context->throwError(QScriptContext::SyntaxError,
QLatin1String("getenv expects 1 argument"));
QVariant v = engine->property("_qbs_procenv");
@@ -424,7 +424,7 @@ static QScriptValue js_getenv(QScriptContext *context, QScriptEngine *engine)
static QScriptValue js_putenv(QScriptContext *context, QScriptEngine *engine)
{
- if (context->argumentCount() < 2)
+ if (Q_UNLIKELY(context->argumentCount() < 2))
return context->throwError(QScriptContext::SyntaxError,
QLatin1String("putenv expects 2 arguments"));
QVariant v = engine->property("_qbs_procenv");
@@ -526,7 +526,7 @@ static QProcessEnvironment getProcessEnvironment(ScriptEngine *engine, EnvType e
ctx->pushScope(scope);
scriptValue = engine->evaluate(setupScript);
ctx->popScope();
- if (scriptValue.isError() || engine->hasUncaughtException()) {
+ if (Q_UNLIKELY(scriptValue.isError() || engine->hasUncaughtException())) {
QString envTypeStr = (envType == BuildEnv ? "build" : "run");
throw Error(QString("Error while setting up %1 environment: %2").arg(envTypeStr, scriptValue.toString()));
}
diff --git a/src/lib/language/moduleloader.cpp b/src/lib/language/moduleloader.cpp
index 06a9fa59b..6ae1b3189 100644
--- a/src/lib/language/moduleloader.cpp
+++ b/src/lib/language/moduleloader.cpp
@@ -239,7 +239,7 @@ void ModuleLoader::handleProductModule(ModuleLoader::ProductContext *productCont
const ItemPtr &item)
{
checkCancelation();
- if (productContext->filesWithProductModule.contains(item->file()))
+ if (Q_UNLIKELY(productContext->filesWithProductModule.contains(item->file())))
throw Error(Tr::tr("Multiple ProductModule items in one product are prohibited."),
item->location());
productContext->filesWithProductModule += item->file();
@@ -277,7 +277,7 @@ void ModuleLoader::resolveDependencies(DependsContext *dependsContext, const Ite
Item::Module baseModuleDesc;
baseModuleDesc.name = baseModuleName;
baseModuleDesc.item = loadModule(dependsContext->product, item, QString(), baseModuleName);
- if (!baseModuleDesc.item)
+ if (Q_UNLIKELY(!baseModuleDesc.item))
throw Error(Tr::tr("Cannot load base qbs module."));
baseModuleDesc.item->setProperty(QLatin1String("getenv"),
BuiltinValue::create(BuiltinValue::GetEnvFunction));
@@ -322,7 +322,7 @@ void ModuleLoader::resolveDependsItem(DependsContext *dependsContext, const Item
checkCancelation();
const QString name = m_evaluator->property(dependsItem, "name").toString().toLower();
const QStringList nameParts = name.split('.');
- if (nameParts.count() > 2) {
+ if (Q_UNLIKELY(nameParts.count() > 2)) {
QString msg = Tr::tr("There cannot be more than one dot in a module name.");
throw Error(msg, dependsItem->location());
}
@@ -330,13 +330,13 @@ void ModuleLoader::resolveDependsItem(DependsContext *dependsContext, const Item
QString superModuleName;
QStringList submodules = toStringList(m_evaluator->property(dependsItem, "submodules"));
if (nameParts.count() == 2) {
- if (!submodules.isEmpty())
+ if (Q_UNLIKELY(!submodules.isEmpty()))
throw Error(Tr::tr("Depends.submodules cannot be used if name contains a dot."),
dependsItem->location());
superModuleName = nameParts.first();
submodules += nameParts.last();
}
- if (submodules.count() > 1 && !dependsItem->id().isEmpty()) {
+ if (Q_UNLIKELY(submodules.count() > 1 && !dependsItem->id().isEmpty())) {
QString msg = Tr::tr("A Depends item with more than one module cannot have an id.");
throw Error(msg, dependsItem->location());
}
@@ -473,7 +473,7 @@ ItemPtr ModuleLoader::searchAndLoadModuleFile(ProductContext *productContext,
}
}
- if (triedToLoadModule)
+ if (Q_UNLIKELY(triedToLoadModule))
throw Error(Tr::tr("Module %1 could not be loaded.").arg(fullModuleName(moduleName)));
return ItemPtr();
@@ -595,7 +595,7 @@ void ModuleLoader::instantiateModule(ProductContext *productContext, const ItemP
for (QVariantMap::const_iterator vmit = userModuleProperties.begin();
vmit != userModuleProperties.end(); ++vmit)
{
- if (!moduleInstance->hasProperty(vmit.key()))
+ if (Q_UNLIKELY(!moduleInstance->hasProperty(vmit.key())))
throw Error(Tr::tr("Unknown property: %1.%2").arg(fullModuleName(moduleName), vmit.key()));
moduleInstance->setProperty(vmit.key(), VariantValue::create(vmit.value()));
}
@@ -628,7 +628,7 @@ void ModuleLoader::resolveProbes(const ItemPtr &item)
void ModuleLoader::resolveProbe(const ItemPtr &parent, const ItemPtr &probe)
{
const JSSourceValueConstPtr configureScript = probe->sourceProperty(QLatin1String("configure"));
- if (!configureScript)
+ if (Q_UNLIKELY(!configureScript))
throw Error(Tr::tr("Probe.configure must be set."), probe->location());
typedef QPair<QString, QScriptValue> ProbeProperty;
QList<ProbeProperty> probeBindings;
@@ -637,7 +637,7 @@ void ModuleLoader::resolveProbe(const ItemPtr &parent, const ItemPtr &probe)
if (name == QLatin1String("configure"))
continue;
QScriptValue sv = m_evaluator->property(probe, name);
- if (sv.isError()) {
+ if (Q_UNLIKELY(sv.isError())) {
ValuePtr value = obj->property(name);
throw Error(sv.toString(), value ? value->location() : CodeLocation());
}
@@ -654,7 +654,7 @@ void ModuleLoader::resolveProbe(const ItemPtr &parent, const ItemPtr &probe)
foreach (const ProbeProperty &b, probeBindings)
scope.setProperty(b.first, b.second);
QScriptValue sv = m_engine->evaluate(configureScript->sourceCode());
- if (sv.isError())
+ if (Q_UNLIKELY(sv.isError()))
throw Error(sv.toString(), configureScript->location());
foreach (const ProbeProperty &b, probeBindings) {
const QVariant newValue = scope.property(b.first).toVariant();
@@ -679,7 +679,7 @@ bool ModuleLoader::checkItemCondition(const ItemPtr &item)
// Item doesn't have a condition binding. Handled as true.
return true;
}
- if (value.isError()) {
+ if (Q_UNLIKELY(value.isError())) {
CodeLocation location;
ValuePtr prop = item->property("condition");
if (prop && prop->type() == Value::JSSourceValueType)
diff --git a/src/lib/language/projectresolver.cpp b/src/lib/language/projectresolver.cpp
index 7039719d5..1214451a1 100644
--- a/src/lib/language/projectresolver.cpp
+++ b/src/lib/language/projectresolver.cpp
@@ -104,7 +104,7 @@ void ProjectResolver::checkCancelation() const
bool ProjectResolver::boolValue(const ItemConstPtr &item, const QString &name, bool defaultValue) const
{
QScriptValue v = m_evaluator->property(item, name);
- if (v.isError()) {
+ if (Q_UNLIKELY(v.isError())) {
ValuePtr value = item->property(name);
throw Error(v.toString(), value ? value->location() : CodeLocation());
}
@@ -122,7 +122,7 @@ QString ProjectResolver::stringValue(const ItemConstPtr &item, const QString &na
const QString &defaultValue) const
{
QScriptValue v = m_evaluator->property(item, name);
- if (v.isError()) {
+ if (Q_UNLIKELY(v.isError())) {
ValuePtr value = item->property(name);
throw Error(v.toString(), value ? value->location() : CodeLocation());
}
@@ -134,7 +134,7 @@ QString ProjectResolver::stringValue(const ItemConstPtr &item, const QString &na
QStringList ProjectResolver::stringListValue(const ItemConstPtr &item, const QString &name) const
{
QScriptValue v = m_evaluator->property(item, name);
- if (v.isError()) {
+ if (Q_UNLIKELY(v.isError())) {
ValuePtr value = item->property(name);
throw Error(v.toString(), value ? value->location() : CodeLocation());
}
@@ -341,7 +341,7 @@ void ProjectResolver::resolveGroup(const ItemPtr &item)
QStringList files = stringListValue(item, QLatin1String("files"));
const QStringList fileTagsFilter = stringListValue(item, QLatin1String("fileTagsFilter"));
if (!fileTagsFilter.isEmpty()) {
- if (!files.isEmpty())
+ if (Q_UNLIKELY(!files.isEmpty()))
throw Error(Tr::tr("Group.files and Group.fileTagsFilters are exclusive."),
item->location());
ArtifactPropertiesPtr aprops = ArtifactProperties::create();
@@ -352,7 +352,7 @@ void ProjectResolver::resolveGroup(const ItemPtr &item)
m_productContext->product->artifactProperties += aprops;
return;
}
- if (files.isEmpty() && !item->hasProperty(QLatin1String("files"))) {
+ if (Q_UNLIKELY(files.isEmpty() && !item->hasProperty(QLatin1String("files")))) {
// Yield an error if Group without files binding is encountered.
// An empty files value is OK but a binding must exist.
throw Error(Tr::tr("Group without files is not allowed."),
@@ -423,14 +423,14 @@ void ProjectResolver::resolveRule(const ItemPtr &item)
// read artifacts
bool hasAlwaysUpdatedArtifact = false;
foreach (const ItemPtr &child, item->children()) {
- if (child->typeName() != QLatin1String("Artifact"))
+ if (Q_UNLIKELY(child->typeName() != QLatin1String("Artifact")))
throw Error(Tr::tr("'Rule' can only have children of type 'Artifact'."),
child->location());
resolveRuleArtifact(rule, child, &hasAlwaysUpdatedArtifact);
}
- if (!hasAlwaysUpdatedArtifact)
+ if (Q_UNLIKELY(!hasAlwaysUpdatedArtifact))
throw Error(Tr::tr("At least one output artifact of a rule "
"must have alwaysUpdated set to true."),
item->location());
@@ -561,12 +561,12 @@ void ProjectResolver::resolveTransformer(const ItemPtr &item)
rtrafo->transform = transform;
foreach (const ItemConstPtr &child, item->children()) {
- if (child->typeName() != QLatin1String("Artifact"))
+ if (Q_UNLIKELY(child->typeName() != QLatin1String("Artifact")))
throw Error(Tr::tr("Transformer: wrong child type '%0'.").arg(child->typeName()));
SourceArtifactPtr artifact = SourceArtifact::create();
artifact->properties = m_productContext->product->properties;
QString fileName = stringValue(child, "fileName");
- if (fileName.isEmpty())
+ if (Q_UNLIKELY(fileName.isEmpty()))
throw Error(Tr::tr("Artifact fileName must not be empty."));
artifact->absoluteFilePath = FileInfo::resolvePath(m_productContext->product->project->buildDirectory,
fileName);
@@ -627,7 +627,7 @@ void ProjectResolver::resolveProductDependencies()
productInfo.usedProducts) {
ResolvedProductPtr usedProduct
= m_projectContext->productsByName.value(dependency.name);
- if (!usedProduct)
+ if (Q_UNLIKELY(!usedProduct))
throw Error(Tr::tr("Product dependency '%1' not found.").arg(dependency.name),
productItem->location());
const ItemPtr usedProductItem = m_projectContext->productItemMap.value(usedProduct);
@@ -649,7 +649,7 @@ void ProjectResolver::resolveProductDependencies()
const QString &usedProductName = dependency.name;
ResolvedProductPtr usedProduct
= m_projectContext->productsByName.value(usedProductName);
- if (!usedProduct)
+ if (Q_UNLIKELY(!usedProduct))
throw Error(Tr::tr("Product dependency '%1' not found.").arg(usedProductName),
productItem->location());
rproduct->dependencies.insert(usedProduct);
@@ -762,7 +762,7 @@ QVariantMap ProjectResolver::evaluateProperties(const ItemPtr &item,
break;
}
const QScriptValue scriptValue = m_evaluator->property(item, it.key());
- if (scriptValue.isError())
+ if (Q_UNLIKELY(scriptValue.isError()))
throw Error(scriptValue.toString(), it.value()->location());
QVariant v = scriptValue.toVariant();
if (pd.type == PropertyDeclaration::Path)
@@ -816,7 +816,7 @@ void ProjectResolver::callItemFunction(const ItemFuncMap &mappings,
{
const QByteArray typeName = item->typeName().toLocal8Bit();
ItemFuncPtr f = mappings.value(typeName);
- if (!f) {
+ if (Q_UNLIKELY(!f)) {
const QString msg = Tr::tr("Unexpected item type '%1'.");
throw Error(msg.arg(item->typeName()), item->location());
}
diff --git a/src/lib/language/scriptengine.cpp b/src/lib/language/scriptengine.cpp
index d8c80f903..e28140e28 100644
--- a/src/lib/language/scriptengine.cpp
+++ b/src/lib/language/scriptengine.cpp
@@ -90,7 +90,7 @@ void ScriptEngine::import(const JsImport &jsImport, QScriptValue scope, QScriptV
if (debugJSImports)
m_logger.qbsDebug() << "[ENGINE] " << fileName << " (cache miss)";
QFile file(fileName);
- if (!file.open(QFile::ReadOnly))
+ if (Q_UNLIKELY(!file.open(QFile::ReadOnly)))
throw Error(tr("Cannot open '%1'.").arg(fileName));
const QString sourceCode = QTextStream(&file).readAll();
file.close();
@@ -181,7 +181,7 @@ void ScriptEngine::importProgram(const QScriptProgram &program, const QScriptVal
if (scope.isObject())
currentContext()->popScope();
popContext();
- if (result.isError())
+ if (Q_UNLIKELY(result.isError()))
throw Error(tr("Error when importing '%1': %2").arg(program.fileName(), result.toString()));
// If targetObject is already an object, it doesn't get overwritten but enhanced by the
diff --git a/src/lib/tools/persistence.cpp b/src/lib/tools/persistence.cpp
index a4be67ad8..04d8cfcf2 100644
--- a/src/lib/tools/persistence.cpp
+++ b/src/lib/tools/persistence.cpp
@@ -152,7 +152,7 @@ void PersistentPool::storeString(const QString &t)
QString PersistentPool::loadString(int id)
{
- if (id < 0)
+ if (Q_UNLIKELY(id < 0))
throw Error("loadString with negative id called");
if (id >= m_stringStorage.count()) {
diff --git a/src/lib/tools/profile.cpp b/src/lib/tools/profile.cpp
index a4eb9c8b8..670551f96 100644
--- a/src/lib/tools/profile.cpp
+++ b/src/lib/tools/profile.cpp
@@ -201,7 +201,7 @@ QStringList Profile::allKeysInternal(Profile::KeySelection selection,
void Profile::extendAndCheckProfileChain(QStringList &chain) const
{
chain << m_name;
- if (chain.count(m_name) > 1) {
+ if (Q_UNLIKELY(chain.count(m_name) > 1)) {
throw Error(Internal::Tr::tr("Circular profile inheritance. Cycle is '%1'.")
.arg(chain.join(QLatin1String(" -> "))));
}
diff --git a/src/lib/tools/qbsassert.h b/src/lib/tools/qbsassert.h
index 0410d88d8..686c08ab5 100644
--- a/src/lib/tools/qbsassert.h
+++ b/src/lib/tools/qbsassert.h
@@ -42,7 +42,7 @@ void QBS_EXPORT throwAssertLocation(const char *condition, const char *file, int
} // namespace qbs
#define QBS_ASSERT(cond, action)\
- if (cond) {} else {\
+ if (Q_LIKELY(cond)) {} else {\
::qbs::Internal::writeAssertLocation(#cond, __FILE__, __LINE__); action;\
} do {} while (0)
@@ -51,7 +51,7 @@ void QBS_EXPORT throwAssertLocation(const char *condition, const char *file, int
#define QBS_CHECK(cond)\
do {\
- if (cond) {} else {\
+ if (Q_LIKELY(cond)) {} else {\
::qbs::Internal::throwAssertLocation(#cond, __FILE__, __LINE__);\
}\
} while (0)