QString optimizations.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-04-22 18:32:55 +03:00
parent e845453f95
commit 862860f016
10 changed files with 73 additions and 80 deletions

View file

@ -180,21 +180,23 @@ int ReadVal(const QString &formula, qreal &val, const QLocale &locale, const QCh
Q_UNUSED(decimalPoint) Q_UNUSED(decimalPoint)
Q_UNUSED(groupSeparator) Q_UNUSED(groupSeparator)
QSet<QChar> reserved; QSet<QChar> reserved
reserved << positiveSign {
<< negativeSign positiveSign,
<< sign0 negativeSign,
<< sign1 sign0,
<< sign2 sign1,
<< sign3 sign2,
<< sign4 sign3,
<< sign5 sign4,
<< sign6 sign5,
<< sign7 sign6,
<< sign8 sign7,
<< sign9 sign8,
<< expUpper sign9,
<< expLower; expUpper,
expLower
};
if (reserved.contains(decimal) || reserved.contains(thousand)) if (reserved.contains(decimal) || reserved.contains(thousand))
{ {
@ -244,7 +246,7 @@ int ReadVal(const QString &formula, qreal &val, const QLocale &locale, const QCh
{ {
if (decimal == cThousand) if (decimal == cThousand)
{// Handle reverse to C locale case: thousand '.', decimal ',' {// Handle reverse to C locale case: thousand '.', decimal ','
const QChar tmpThousand = '@'; const QChar tmpThousand = QLatin1Char('@');
buf.replace(thousand, tmpThousand); buf.replace(thousand, tmpThousand);
buf.replace(decimal, cDecimal); buf.replace(decimal, cDecimal);
buf.replace(tmpThousand, cThousand); buf.replace(tmpThousand, cThousand);

View file

@ -438,52 +438,52 @@ void QmuParser::InitCharSets()
void QmuParser::InitFun() void QmuParser::InitFun()
{ {
// trigonometric helper functions // trigonometric helper functions
DefineFun("degTorad", DegreeToRadian); DefineFun(QStringLiteral("degTorad"), DegreeToRadian);
DefineFun("radTodeg", RadianToDegree); DefineFun(QStringLiteral("radTodeg"), RadianToDegree);
// trigonometric functions // trigonometric functions
DefineFun("sin", qSin); DefineFun(QStringLiteral("sin"), qSin);
DefineFun("cos", qCos); DefineFun(QStringLiteral("cos"), qCos);
DefineFun("tan", qTan); DefineFun(QStringLiteral("tan"), qTan);
DefineFun("sinD", SinD); DefineFun(QStringLiteral("sinD"), SinD);
DefineFun("cosD", CosD); DefineFun(QStringLiteral("cosD"), CosD);
DefineFun("tanD", TanD); DefineFun(QStringLiteral("tanD"), TanD);
// arcus functions // arcus functions
DefineFun("asin", qAsin); DefineFun(QStringLiteral("asin"), qAsin);
DefineFun("acos", qAcos); DefineFun(QStringLiteral("acos"), qAcos);
DefineFun("atan", qAtan); DefineFun(QStringLiteral("atan"), qAtan);
DefineFun("atan2", qAtan2); DefineFun(QStringLiteral("atan2"), qAtan2);
DefineFun("asinD", ASinD); DefineFun(QStringLiteral("asinD"), ASinD);
DefineFun("acosD", ACosD); DefineFun(QStringLiteral("acosD"), ACosD);
DefineFun("atanD", ATanD); DefineFun(QStringLiteral("atanD"), ATanD);
// hyperbolic functions // hyperbolic functions
DefineFun("sinh", Sinh); DefineFun(QStringLiteral("sinh"), Sinh);
DefineFun("cosh", Cosh); DefineFun(QStringLiteral("cosh"), Cosh);
DefineFun("tanh", Tanh); DefineFun(QStringLiteral("tanh"), Tanh);
// arcus hyperbolic functions // arcus hyperbolic functions
DefineFun("asinh", ASinh); DefineFun(QStringLiteral("asinh"), ASinh);
DefineFun("acosh", ACosh); DefineFun(QStringLiteral("acosh"), ACosh);
DefineFun("atanh", ATanh); DefineFun(QStringLiteral("atanh"), ATanh);
// Logarithm functions // Logarithm functions
DefineFun("log2", Log2); DefineFun(QStringLiteral("log2"), Log2);
DefineFun("log10", Log10); DefineFun(QStringLiteral("log10"), Log10);
DefineFun("log", Log10); DefineFun(QStringLiteral("log"), Log10);
DefineFun("ln", qLn); DefineFun(QStringLiteral("ln"), qLn);
// misc // misc
DefineFun("exp", qExp); DefineFun(QStringLiteral("exp"), qExp);
DefineFun("sqrt", qSqrt); DefineFun(QStringLiteral("sqrt"), qSqrt);
DefineFun("sign", Sign); DefineFun(QStringLiteral("sign"), Sign);
DefineFun("rint", Rint); DefineFun(QStringLiteral("rint"), Rint);
DefineFun("r2cm", R2CM); DefineFun(QStringLiteral("r2cm"), R2CM);
DefineFun("csrCm", CSRCm); DefineFun(QStringLiteral("csrCm"), CSRCm);
DefineFun("csrInch", CSRInch); DefineFun(QStringLiteral("csrInch"), CSRInch);
DefineFun("abs", Abs); DefineFun(QStringLiteral("abs"), Abs);
DefineFun("fmod", FMod); DefineFun(QStringLiteral("fmod"), FMod);
// Functions with variable number of arguments // Functions with variable number of arguments
DefineFun("sum", Sum); DefineFun(QStringLiteral("sum"), Sum);
DefineFun("avg", Avg); DefineFun(QStringLiteral("avg"), Avg);
DefineFun("min", Min); DefineFun(QStringLiteral("min"), Min);
DefineFun("max", Max); DefineFun(QStringLiteral("max"), Max);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -436,7 +436,7 @@ void QmuParserBase::SetExpr(const QString &a_sExpr)
// when calling tellg on a stringstream created from the expression after // when calling tellg on a stringstream created from the expression after
// reading a value at the end of an expression. (qmu::QmuParser::IsVal function) // reading a value at the end of an expression. (qmu::QmuParser::IsVal function)
// (tellg returns -1 otherwise causing the parser to ignore the value) // (tellg returns -1 otherwise causing the parser to ignore the value)
QString sBuf(a_sExpr + " " ); QString sBuf(a_sExpr + QChar(' ') );
m_pTokenReader->SetFormula(sBuf); m_pTokenReader->SetFormula(sBuf);
ReInit(); ReInit();
} }

View file

@ -39,8 +39,6 @@
#define QMUP_VERSION "2.6.0" #define QMUP_VERSION "2.6.0"
#define QMUP_VERSION_DATE "20180121; GC" #define QMUP_VERSION_DATE "20180121; GC"
#define QMUP_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// Detect whether the compiler supports C++11 noexcept exception specifications. // Detect whether the compiler supports C++11 noexcept exception specifications.
# if defined(__clang__) # if defined(__clang__)
# if __has_feature(cxx_noexcept) # if __has_feature(cxx_noexcept)

View file

@ -368,7 +368,7 @@ int QmuParserTokenReader::ExtractOperatorToken ( QString &a_sTok, int a_iPos ) c
{ {
// There is still the chance of having to deal with an operator consisting exclusively // There is still the chance of having to deal with an operator consisting exclusively
// of alphabetic characters. // of alphabetic characters.
return ExtractToken ( QMUP_CHARS, a_sTok, a_iPos ); return ExtractToken (QStringLiteral("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), a_sTok, a_iPos );
} }
} }
QT_WARNING_POP QT_WARNING_POP

View file

@ -235,9 +235,8 @@ void VToolFlippingByAxis::SaveOptions(QDomElement &tag, QSharedPointer<VGObject>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolFlippingByAxis::MakeToolTip() const QString VToolFlippingByAxis::MakeToolTip() const
{ {
const QString toolTip = QString("<tr> <td><b>%1:</b> %2</td> </tr>") return QStringLiteral("<tr> <td><b>%1:</b> %2</td> </tr>")
.arg(tr("Origin point"), OriginPointName()); .arg(tr("Origin point"), OriginPointName());
return toolTip;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -222,10 +222,9 @@ void VToolFlippingByLine::SaveOptions(QDomElement &tag, QSharedPointer<VGObject>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolFlippingByLine::MakeToolTip() const QString VToolFlippingByLine::MakeToolTip() const
{ {
const QString toolTip = QString("<tr> <td><b>%1:</b> %2</td> </tr>" return QStringLiteral("<tr> <td><b>%1:</b> %2</td> </tr>"
"<tr> <td><b>%3:</b> %4</td> </tr>") "<tr> <td><b>%3:</b> %4</td> </tr>")
.arg(tr("First line point"), FirstLinePointName(), tr("Second line point"), SecondLinePointName()); .arg(tr("First line point"), FirstLinePointName(), tr("Second line point"), SecondLinePointName());
return toolTip;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -668,14 +668,11 @@ QT_WARNING_POP
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VAbstractOperation::ComplexPointToolTip(quint32 itemId) const QString VAbstractOperation::ComplexPointToolTip(quint32 itemId) const
{ {
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(itemId); return QStringLiteral("<table>"
"<tr> <td><b>%1:</b> %2</td> </tr>"
const QString toolTip = QString("<table>" "%3"
"<tr> <td><b>%1:</b> %2</td> </tr>" "</table>")
"%3" .arg(tr("Label"), VAbstractTool::data.GetGObject(itemId)->name(), MakeToolTip());
"</table>")
.arg(tr("Label"), point->name(), MakeToolTip());
return toolTip;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -413,7 +413,7 @@ QString VToolMove::OriginPointName() const
{ {
try try
{ {
return VAbstractTool::data.GetGObject(origPointId)->name(); return VAbstractTool::data.GetGObject(origPointId)->name();
} }
catch (const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
@ -504,10 +504,10 @@ void VToolMove::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolMove::MakeToolTip() const QString VToolMove::MakeToolTip() const
{ {
const QString toolTip = QString("<tr> <td><b>%1:</b> %2°</td> </tr>" return QStringLiteral("<tr> <td><b>%1:</b> %2°</td> </tr>"
"<tr> <td><b>%3:</b> %4 %5</td> </tr>" "<tr> <td><b>%3:</b> %4 %5</td> </tr>"
"<tr> <td><b>%6:</b> %7°</td> </tr>" "<tr> <td><b>%6:</b> %7°</td> </tr>"
"<tr> <td><b>%8:</b> %9</td> </tr>") "<tr> <td><b>%8:</b> %9</td> </tr>")
.arg(tr("Angle")) // 1 .arg(tr("Angle")) // 1
.arg(GetFormulaAngle().getDoubleValue()) // 2 .arg(GetFormulaAngle().getDoubleValue()) // 2
.arg(tr("Length")) // 3 .arg(tr("Length")) // 3
@ -517,7 +517,6 @@ QString VToolMove::MakeToolTip() const
.arg(GetFormulaRotationAngle().getDoubleValue()) // 7 .arg(GetFormulaRotationAngle().getDoubleValue()) // 7
.arg(tr("Rotation origin point"), // 8 .arg(tr("Rotation origin point"), // 8
OriginPointName()); // 9 OriginPointName()); // 9
return toolTip;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -371,11 +371,10 @@ void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolRotation::MakeToolTip() const QString VToolRotation::MakeToolTip() const
{ {
const QString toolTip = QString("<tr> <td><b>%1:</b> %2</td> </tr>" return QStringLiteral("<tr> <td><b>%1:</b> %2</td> </tr>"
"<tr> <td><b>%3:</b> %4°</td> </tr>") "<tr> <td><b>%3:</b> %4°</td> </tr>")
.arg(tr("Origin point"), OriginPointName(), tr("Rotation angle")) .arg(tr("Origin point"), OriginPointName(), tr("Rotation angle"))
.arg(GetFormulaAngle().getDoubleValue()); .arg(GetFormulaAngle().getDoubleValue());
return toolTip;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------