From 54fbcfe15cbd0ce5dec016482ff893ef952431bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 23 Nov 2017 14:54:29 +0100 Subject: [PATCH] [poincare] In trigonometry, avoid to loop on trigo table if the expression does have the right type Change-Id: I2cd5169df6709943aeddf96d098aa8d8275465d0 --- poincare/src/trigonometry.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/poincare/src/trigonometry.cpp b/poincare/src/trigonometry.cpp index 37b87d77c..753f25b75 100644 --- a/poincare/src/trigonometry.cpp +++ b/poincare/src/trigonometry.cpp @@ -180,6 +180,17 @@ Expression * Trigonometry::table(const Expression * e, Expression::Type type, Co int trigonometricFunctionIndex = type == Expression::Type::Cosine || type == Expression::Type::ArcCosine ? 2 : (type == Expression::Type::Sine || type == Expression::Type::ArcSine ? 3 : 4); int inputIndex = type == Expression::Type::ArcCosine || type == Expression::Type::ArcSine || type == Expression::Type::ArcTangent ? trigonometricFunctionIndex : angleUnitIndex; int outputIndex = type == Expression::Type::ArcCosine || type == Expression::Type::ArcSine || type == Expression::Type::ArcTangent ? angleUnitIndex : trigonometricFunctionIndex; + + /* Avoid looping if we can exclude quickly that the e is in the table */ + if (inputIndex == 0 && e->type() != Expression::Type::Rational) { + return nullptr; + } + if (inputIndex == 1 && e->type() != Expression::Type::Rational && e->type() != Expression::Type::Multiplication && e->type() != Expression::Type::Symbol) { + return nullptr; + } + if (inputIndex >1 && e->type() != Expression::Type::Rational && e->type() != Expression::Type::Multiplication && e->type() != Expression::Type::Power && e->type() != Expression::Type::Addition) { + return nullptr; + } for (int i = 0; i < k_numberOfEntries; i++) { Expression * input = Expression::parse(cheatTable[i][inputIndex]); if (input == nullptr) {