From 589021d6eb5d7330d12d0b2efe76dff77f10b0b6 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 24 Apr 2017 11:50:33 +0200 Subject: Merge caches with same key in Evaluator Reduce hash lookups and memory footprint. ========== Performance data for Resolving ========== Old instruction count: 2465977485 New instruction count: 2457362647 Relative change: -1 % Old peak memory usage: 21248960 Bytes New peak memory usage: 21237680 Bytes Relative change: -1 % ========== Performance data for Rule Execution ========== Old instruction count: 4898426038 New instruction count: 4857983226 Relative change: -1 % Old peak memory usage: 27604240 Bytes New peak memory usage: 27593424 Bytes Relative change: -1 % ========== Performance data for Null Build ========== Old instruction count: 4509789474 New instruction count: 4490616946 Relative change: -1 % Old peak memory usage: 30680456 Bytes New peak memory usage: 30670784 Bytes Relative change: -1 % Change-Id: Ie613447cf9da4bc3d2bfdab42c9a9b5ace643540 Reviewed-by: Christian Kandeler --- src/lib/corelib/language/evaluatorscriptclass.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/lib/corelib/language/evaluatorscriptclass.cpp') diff --git a/src/lib/corelib/language/evaluatorscriptclass.cpp b/src/lib/corelib/language/evaluatorscriptclass.cpp index c68a195bc..50aa23707 100644 --- a/src/lib/corelib/language/evaluatorscriptclass.cpp +++ b/src/lib/corelib/language/evaluatorscriptclass.cpp @@ -101,15 +101,6 @@ public: } private: - QScriptValue importScope(Evaluator *evaluator, const FileContextConstPtr &file) - { - try { - return evaluator->importScope(file); - } catch (const ErrorInfo &e) { - return evaluator->engine()->currentContext()->throwError(e.toString()); - } - } - void setupConvenienceProperty(const QString &conveniencePropertyName, QScriptValue *extraScope, const QScriptValue &scriptValue) { @@ -162,6 +153,8 @@ private: for (int i = 0; i < value->alternatives().count(); ++i) { const JSSourceValue::Alternative *alternative = 0; alternative = &value->alternatives().at(i); + const Evaluator::FileContextScopes fileCtxScopes + = data->evaluator->fileContextScopes(value->file()); if (!conditionScopeItem) { // We have to differentiate between module instances and normal items here. // @@ -194,14 +187,14 @@ private: ? data->item->scope() : data->item; conditionScope = data->evaluator->scriptValue(conditionScopeItem); QBS_ASSERT(conditionScope.isObject(), return); - conditionFileScope = data->evaluator->fileScope(value->file()); + conditionFileScope = fileCtxScopes.fileScope; } scriptContext->pushScope(conditionFileScope); pushItemScopes(conditionScopeItem); if (alternative->value->definingItem()) pushItemScopes(alternative->value->definingItem()); scriptContext->pushScope(conditionScope); - const QScriptValue theImportScope = importScope(data->evaluator, value->file()); + const QScriptValue &theImportScope = fileCtxScopes.importScope; if (theImportScope.isError()) { scriptContext->popScope(); scriptContext->popScope(); @@ -275,7 +268,9 @@ private: setupConvenienceProperty(QLatin1String("original"), &extraScope, originalValue); } - pushScope(data->evaluator->fileScope(value->file())); + const Evaluator::FileContextScopes fileCtxScopes + = data->evaluator->fileContextScopes(value->file()); + pushScope(fileCtxScopes.fileScope); pushItemScopes(data->item); if (itemOfProperty && itemOfProperty->type() != ItemType::ModuleInstance) { // Own properties of module instances must not have the instance itself in the scope. @@ -284,7 +279,7 @@ private: if (value->definingItem()) pushItemScopes(value->definingItem()); pushScope(extraScope); - const QScriptValue theImportScope = importScope(data->evaluator, value->file()); + const QScriptValue &theImportScope = fileCtxScopes.importScope; if (theImportScope.isError()) { *result = theImportScope; } else { -- cgit v1.2.3