[Kst] kdeextragear-2/kst/kst
George Staikos
staikos at kde.org
Fri Feb 13 22:26:13 CET 2004
CVS commit by staikos:
don't re-optimize, reparse, etc when it's not necessary.
M +0 -3 enodes.cpp 1.6
M +34 -25 kstequationcurve.cpp 1.45
M +6 -1 kstequationcurve.h 1.24
--- kdeextragear-2/kst/kst/enodes.cpp #1.5:1.6
@@ -373,9 +373,6 @@ Data::Data(char *name)
n.truncate(n.length() - 1);
_vector = *KST::vectorList.findTag(n);
- // FIXME: no updates!!
if (!_vector) {
_scalar = *KST::scalarList.findTag(n);
- } else {
- _vector->update(-1);
}
}
--- kdeextragear-2/kst/kst/kstequationcurve.cpp #1.44:1.45
@@ -149,6 +149,6 @@ void KstEquationCurve::commonConstructor
const QString &in_equation,
const QColor &in_color) {
+ _pe = 0L;
_typeString = i18n("Equation");
- Equation = in_equation;
setHasPoints(false);
setHasLines(true);
@@ -166,4 +166,6 @@ void KstEquationCurve::commonConstructor
IsValid = false;
NumNew = NumShifted = 0;
+
+ Equation = in_equation;
}
@@ -242,7 +244,12 @@ void KstEquationCurve::save(QTextStream
}
-void KstEquationCurve::setEquation(const QString &in_fn) {
+void KstEquationCurve::setEquation(const QString& in_fn) {
Equation = in_fn;
+ VectorsUsed.clear();
NS = 2; // reset the updating
+ if (_pe) {
+ delete _pe;
+ _pe = 0L;
+ }
}
@@ -304,5 +311,4 @@ extern "C" struct yy_buffer_state *yy_sc
/* */
/************************************************************************/
-// FIXME: Optimize me
bool KstEquationCurve::FillY(bool force) {
unsigned i_v;
@@ -311,14 +317,4 @@ bool KstEquationCurve::FillY(bool force)
int ns;
- kdDebug() << "Trying my parser on [" << Equation << "]." << endl;
- // FIXME: cache this
- yy_scan_string(Equation.latin1());
- int rc = yyparse();
- kdDebug() << "My parser returned: " << rc << endl;
- Equation::Node *pe = static_cast<Equation::Node*>(ParsedEquation);
- VectorsUsed.clear();
- // Inefficient
- pe->collectVectors(VectorsUsed);
-
// determine value of Interp
if (DoInterp) {
@@ -392,19 +388,32 @@ bool KstEquationCurve::FillY(bool force)
KstVectorPtr iv = (*_xVector);
- if (rc == 0) {
Equation::Context ctx;
ctx.sampleCount = NS;
- pe->fold(&ctx);
- clock_t c_in = clock();
- for (ctx.i = i0; ctx.i < NS; ++ctx.i) {
- ctx.x = iv->interpolate(ctx.i, NS);
- rawv[ctx.i] = pe->value(&ctx);
- }
- kdDebug() << "Execution time: " << clock() - c_in << endl;
+
+ if (!_pe) {
+ if (Equation.isEmpty()) {
+ return true;
}
+
+ yy_scan_string(Equation.latin1());
+ int rc = yyparse();
+ if (rc == 0) {
+ _pe = static_cast<Equation::Node*>(ParsedEquation);
+ _pe->fold(&ctx);
+ _pe->collectVectors(VectorsUsed);
+ ParsedEquation = 0L;
+ } else {
delete (Equation::Node*)ParsedEquation;
ParsedEquation = 0L;
+ return false;
+ }
+ }
- return rc == 0;
+ for (ctx.i = i0; ctx.i < NS; ++ctx.i) {
+ ctx.x = iv->interpolate(ctx.i, NS);
+ rawv[ctx.i] = _pe->value(&ctx);
+ }
+
+ return true;
}
--- kdeextragear-2/kst/kst/kstequationcurve.h #1.23:1.24
@@ -16,5 +16,5 @@
***************************************************************************/
-/** A class for handling power spectra for kst
+/** A class for handling equations for kst
*@author C. Barth Netterfield
*/
@@ -30,4 +30,8 @@
#define MAX_DIV_REG 100
+namespace Equation {
+ class Node;
+}
+
class KstEquationCurve : public KstBaseCurve {
public:
@@ -97,4 +101,5 @@ private:
static const QString OUTVECTOR;
KstVectorMap::Iterator _xVector, _yVector;
+ Equation::Node *_pe;
};
More information about the Kst
mailing list