From cd19fe14cb380a328819db0ccabc9be1e67ec068 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 14 May 2015 19:20:34 +0300 Subject: [PATCH] Optimization for case when expression has only function. Example fmod(5;2). --HG-- branch : develop --- src/app/container/calculator.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 0f065a546..084fc266a 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -123,6 +123,15 @@ qreal Calculator::EvalFormula(const QString &formula) // Remove "-" from tokens list if exist. If don't do that unary minus operation will broken. RemoveAll(tokens, QStringLiteral("-")); + for (int i = 0; i < builInFunctions.size(); ++i) + { + if (tokens.isEmpty()) + { + break; + } + RemoveAll(tokens, builInFunctions.at(i)); + } + if (tokens.isEmpty()) { return result; // We have found only numbers in expression. @@ -187,11 +196,6 @@ void Calculator::InitVariables(const VContainer *data, const QMap } } - if (builInFunctions.contains(i.value())) - {// We have found built-in function - found = true; - } - if (found == false) { throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN, i.value(), formula, i.key());