[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Wed Oct 26 22:22:54 CEST 2005


SVN commit 474597 by staikos:

- experiment with dropping the number of points in the polyline to try to get
better X responsiveness
- use gcc __builtin_expect where available.  it's not always useful where it's
implemented but at least it reminds us where the hot spots are.  also please
keep these up to date because they can have negative impact if the code changes
and they aren't maintained



 M  +44 -33    kstvcurve.cpp  


--- trunk/extragear/graphics/kst/kst/kstvcurve.cpp #474596:474597
@@ -35,8 +35,19 @@
 
 #include <time.h>
 
+#ifndef KDE_IS_LIKELY
+#if __GNUC__ - 0 >= 3
+# define KDE_ISLIKELY( x )    __builtin_expect(!!(x),1)
+# define KDE_ISUNLIKELY( x )  __builtin_expect(!!(x),0)
+#else
+# define KDE_ISLIKELY( x )   ( x )
+# define KDE_ISUNLIKELY( x )  ( x )
+#endif
+#endif
+
 // for painting
-#define MAX_NUM_POLYLINES       1000
+#define MAX_NUM_POLYLINES       300
+//#define MAX_NUM_POLYLINES       1000
 
 static const QString& COLOR_XVECTOR = KGlobal::staticQString("X");
 static const QString& COLOR_YVECTOR = KGlobal::staticQString("Y");
@@ -861,7 +872,7 @@
           rY = yv->interpolate(i_pt, NS);
         }
 
-        if (foundNan) {
+        if (KDE_ISUNLIKELY(foundNan)) {
           if (index > 0) {
             p->drawPolyline(points, 0, index);
           }
@@ -880,7 +891,7 @@
           }
         }
 
-        if (i_pt <= iN) {
+        if (KDE_ISLIKELY(i_pt <= iN)) {
           if (_xLog) {
             rX = logX(rX);
           }
@@ -892,15 +903,15 @@
           last_x1 = X1;
           last_y1 = Y1;
 
-          if (!foundNan) {
+          if (KDE_ISLIKELY(!foundNan)) {
             int X1i = d2i(X1);
             int X2i = d2i(X2);
-            if (X1i == X2i) {
-              if (overlap) {
-                if (Y1 > maxY) {
+            if (KDE_ISLIKELY(X1i == X2i)) {
+              if (KDE_ISLIKELY(overlap)) {
+                if (KDE_ISUNLIKELY(Y1 > maxY)) {
                   maxY = Y1;
                 }
-                if (Y1 < minY) {
+                if (KDE_ISUNLIKELY(Y1 < minY)) {
                   minY = Y1;
                 }
               } else {
@@ -914,9 +925,9 @@
                 overlap = true;
               }
             } else {
-              if (overlap) {
-                if (X2 >= Lx && X2 <= Hx) {
-                  if (maxY <= Hy && minY >= Ly) {
+              if (KDE_ISLIKELY(overlap)) {
+                if (KDE_ISLIKELY(X2 >= Lx && X2 <= Hx)) {
+                  if (KDE_ISUNLIKELY(maxY <= Hy && minY >= Ly)) {
                     int Y2i = d2i(Y2);
                     int maxYi = d2i(maxY);
                     int minYi = d2i(minY);
@@ -925,31 +936,31 @@
                       p->drawPolyline(points, 0, index);
                       index = 0;
                     }
-                    if (minYi == maxYi) {
+                    if (KDE_ISUNLIKELY(minYi == maxYi)) {
                       points.setPoint(index++, X2i, maxYi);
-                    } else if (Y2 == minY) {
+                    } else if (KDE_ISUNLIKELY(Y2 == minY)) {
                       points.setPoint(index++, X2i, maxYi);
                       points.setPoint(index++, X2i, minYi);
-                    } else if (Y2 == maxY) {
+                    } else if (KDE_ISUNLIKELY(Y2 == maxY)) {
                       points.setPoint(index++, X2i, minYi);
                       points.setPoint(index++, X2i, maxYi);
                     } else {
                       points.setPoint(index++, X2i, minYi);
                       points.setPoint(index++, X2i, maxYi);
-                      if (Y2 >= Ly && Y2 <= Hy) {
+                      if (KDE_ISLIKELY(Y2 >= Ly && Y2 <= Hy)) {
                         points.setPoint(index++, X2i, Y2i);
                       }
                     }
                     lastPlottedX = X2i;
                     lastPlottedY = Y2i;
                   } else {
-                    if (maxY > Hy && minY <= Hy) {
+                    if (KDE_ISUNLIKELY(maxY > Hy && minY <= Hy)) {
                       maxY = Hy;
                     }
-                    if (minY < Ly && maxY >= Ly) {
+                    if (KDE_ISUNLIKELY(minY < Ly && maxY >= Ly)) {
                       minY = Ly;
                     }
-                    if (minY >= Ly && minY <= Hy && maxY >= Ly && maxY <= Hy) {
+                    if (KDE_ISUNLIKELY(minY >= Ly && minY <= Hy && maxY >= Ly && maxY <= Hy)) {
                       p->drawLine(X2i, d2i(minY), X2i, d2i(maxY));
                     }
                   }
@@ -957,9 +968,9 @@
                 overlap = false;
               }
 
-              if (!((X1 < Lx && X2 < Lx) || (X1 > Hx && X2 > Hx))) {
+              if (KDE_ISLIKELY(!((X1 < Lx && X2 < Lx) || (X1 > Hx && X2 > Hx)))) {
                 // trim the line to be within the plot...
-                if (isinf(X1)) {
+                if (KDE_ISUNLIKELY(isinf(X1))) {
                   Y1 = Y2;
                   if (X1 > 0.0) {
                     X1 = Hx;
@@ -968,7 +979,7 @@
                   }
                 }
 
-                if (isinf(X2)) {
+                if (KDE_ISUNLIKELY(isinf(X2))) {
                   Y2 = Y1;
                   if (X2 > 0.0) {
                     X2 = Hx;
@@ -977,7 +988,7 @@
                   }
                 }
 
-                if (isinf(Y1)) {
+                if (KDE_ISUNLIKELY(isinf(Y1))) {
                   X1 = X2;
                   if (Y1 > 0.0) {
                     Y1 = Hy;
@@ -986,7 +997,7 @@
                   }
                 }
 
-                if (isinf(Y2)) {
+                if (KDE_ISUNLIKELY(isinf(Y2))) {
                   X2 = X1;
                   if (Y2 > 0.0) {
                     Y2 = Hy;
@@ -995,34 +1006,34 @@
                   }
                 }
 
-                if (X1 < Lx && X2 > Lx) {
+                if (KDE_ISUNLIKELY(X1 < Lx && X2 > Lx)) {
                   Y1 = (Y2 - Y1) / (X2 - X1) * (Lx - X1) + Y1;
                   X1 = Lx;
-                } else if (X2 < Lx && X1 > Lx) {
+                } else if (KDE_ISUNLIKELY(X2 < Lx && X1 > Lx)) {
                   Y2 = (Y1 - Y2) / (X1 - X2) * (Lx - X2) + Y2;
                   X2 = Lx;
                 }
 
-                if (X1 < Hx && X2 > Hx) {
+                if (KDE_ISUNLIKELY(X1 < Hx && X2 > Hx)) {
                   Y2 = (Y2 - Y1) / (X2 - X1) * (Hx - X1) + Y1;
                   X2 = Hx;
-                } else if (X2 < Hx && X1 > Hx) {
+                } else if (KDE_ISUNLIKELY(X2 < Hx && X1 > Hx)) {
                   Y1 = (Y1 - Y2) / (X1 - X2) * (Hx - X2) + Y2;
                   X1 = Hx;
                 }
 
-                if (Y1 < Ly && Y2 > Ly) {
+                if (KDE_ISUNLIKELY(Y1 < Ly && Y2 > Ly)) {
                   X1 = (X2 - X1) / (Y2 - Y1) * (Ly - Y1) + X1;
                   Y1 = Ly;
-                } else if (Y2 < Ly && Y1 > Ly) {
+                } else if (KDE_ISUNLIKELY(Y2 < Ly && Y1 > Ly)) {
                   X2 = (X1 - X2) / (Y1 - Y2) * (Ly - Y2) + X2;
                   Y2 = Ly;
                 }
 
-                if (Y1 < Hy && Y2 > Hy) {
+                if (KDE_ISUNLIKELY(Y1 < Hy && Y2 > Hy)) {
                   X2 = (X2 - X1) / (Y2 - Y1) * (Hy - Y1) + X1;
                   Y2 = Hy;
-                } else if (Y2 < Hy && Y1 > Hy) {
+                } else if (KDE_ISUNLIKELY(Y2 < Hy && Y1 > Hy)) {
                   X1 = (X1 - X2) / (Y1 - Y2) * (Hy - Y2) + X2;
                   Y1 = Hy;
                 }
@@ -1034,7 +1045,7 @@
                   int X2i = d2i(X2);
                   int Y2i = d2i(Y2);
 
-                  if (index == 0) {
+                  if (KDE_ISUNLIKELY(index == 0)) {
                     points.setPoint(index++, X2i, Y2i);
                     points.setPoint(index++, X1i, Y1i);
                   } else if (lastPlottedX == X2i &&
@@ -1042,7 +1053,7 @@
                         index < MAX_NUM_POLYLINES) {
                       points.setPoint(index++, X1i, Y1i);
                   } else {
-                    if (index > 1) {
+                    if (KDE_ISLIKELY(index > 1)) {
                       p->drawPolyline(points, 0, index);
                     }
                     index = 0;


More information about the Kst mailing list