[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Wed Oct 26 21:49:55 CEST 2005


SVN commit 474581 by staikos:

getIndexNearX was changed to an inline function - it was called at least twice
per paint, was a virtual function, and was doing unnecessary lookups.  it's not
called anywhere externally.


 M  +9 -16     kstvcurve.cpp  
 M  +1 -4      kstvcurve.h  


--- trunk/extragear/graphics/kst/kst/kstvcurve.cpp #474580:474581
@@ -554,17 +554,11 @@
 }
 
 
-int KstVCurve::getIndexNearX(double x) const {
-  KstVectorPtr xv = *_inputVectors.find(COLOR_XVECTOR);
-  KstVectorPtr yv = *_inputVectors.find(COLOR_YVECTOR);
-  if (!xv || !yv) {
-    return 0; // anything better we can do?
-  }
-
+inline int indexNearX(double x, KstVectorPtr& xv, int NS) {
   // monotonically rising: we can do a binary search
   // should be reasonably fast
   if (xv->isRising()) {
-    int i_top = sampleCount() - 1;
+    int i_top = NS - 1;
     int i_bot = 0;
 
     // don't pre-check for x outside of the curve since this is not
@@ -588,12 +582,11 @@
   } else {
     // Oh Oh... not monotonically rising - we have to search the entire curve!
     // May be unbearably slow for large vectors
-    int n = sampleCount();
     double rX = xv->interpolate(0, NS);
-    double dx0 = fabs(x-rX);
+    double dx0 = fabs(x - rX);
     int i0 = 0;
 
-    for (int i = 1; i < n; ++i) {
+    for (int i = 1; i < NS; ++i) {
       rX = xv->interpolate(i, NS);
       double dx = fabs(x - rX);
       if (dx < dx0) {
@@ -621,7 +614,7 @@
   int sc = sampleCount();
 
   if (xv->isRising()) {
-    iN = i0 = getIndexNearX(x);
+    iN = i0 = indexNearX(x, xv, NS);
 
     xi = xv->interpolate(i0, NS);
     while (i0 > 0 && x-dx_per_pix < xi) {
@@ -791,11 +784,11 @@
     int width = kMax(lineWidth(), penWidth);
 
     if (xv->isRising()) {
-      i0 = getIndexNearX(XMin);
+      i0 = indexNearX(XMin, xv, NS);
       if (i0 > 0) {
         --i0;
       }
-      iN = getIndexNearX(XMax);
+      iN = indexNearX(XMax, xv, NS);
       if (iN < sampleCount() - 1) {
         ++iN;
       }
@@ -1483,8 +1476,8 @@
   // get range of the curve to search for min/max
   int i0, iN;
   if (xv->isRising()) {
-    i0 = getIndexNearX(xFrom);
-    iN = getIndexNearX(xTo);
+    i0 = indexNearX(xFrom, xv, NS);
+    iN = indexNearX(xTo, xv, NS);
   } else {
     i0 = 0;
     iN = sampleCount() - 1;
--- trunk/extragear/graphics/kst/kst/kstvcurve.h #474580:474581
@@ -39,7 +39,6 @@
     virtual UpdateType update(int update_counter = -1);
     virtual QString propertyString() const;
     
-    virtual int getIndexNearX(double x) const;
     virtual int getIndexNearXY(double x, double dx, double y) const;
 
     virtual bool hasXError() const;
@@ -150,10 +149,8 @@
     virtual KstDataObjectPtr providerDataObject() const;
 
   private:
-    inline void commonConstructor(const QString &in_tag,
-        const QColor &in_color);
+    inline void commonConstructor(const QString& in_tag, const QColor& in_color);
 
-    
     double MeanY;
     
     int BarStyle;


More information about the Kst mailing list