OSDN Git Service

do not buffer in QX11PaintEngine::drawPoints() methods
authorIvailo Monev <xakepa10@gmail.com>
Sun, 2 Aug 2020 04:36:43 +0000 (07:36 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 2 Aug 2020 04:36:43 +0000 (07:36 +0300)
twice as fast on some line drawing benchmarks with no noticable loss in
other cases

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/gui/painting/qpaintengine_x11.cpp

index 14d1c9b..9ecae44 100644 (file)
@@ -928,26 +928,20 @@ void QX11PaintEngine::drawPoints(const QPoint *points, int pointCount)
         return;
     }
 
-    static const int BUF_SIZE = 1024;
-    XPoint xPoints[BUF_SIZE];
+    XPoint xPoints[pointCount];
     int i = 0, j = 0;
     while (i < pointCount) {
-        while (i < pointCount && j < BUF_SIZE) {
-            const QPoint &xformed = d->matrix.map(points[i]);
-            int x = xformed.x();
-            int y = xformed.y();
-            if (x >= SHRT_MIN && y >= SHRT_MIN && x < SHRT_MAX && y < SHRT_MAX) {
-                xPoints[j].x = x;
-                xPoints[j].y = y;
-                ++j;
-            }
-            ++i;
+        const QPoint &xformed = d->matrix.map(points[i]);
+        int x = xformed.x();
+        int y = xformed.y();
+        if (x >= SHRT_MIN && y >= SHRT_MIN && x < SHRT_MAX && y < SHRT_MAX) {
+            xPoints[j].x = x;
+            xPoints[j].y = y;
+            ++j;
         }
-        if (j)
-            XDrawPoints(d->dpy, d->hd, d->gc, xPoints, j, CoordModeOrigin);
-
-        j = 0;
+        ++i;
     }
+    XDrawPoints(d->dpy, d->hd, d->gc, xPoints, j, CoordModeOrigin);
 }
 
 void QX11PaintEngine::drawPoints(const QPointF *points, int pointCount)
@@ -986,27 +980,21 @@ void QX11PaintEngine::drawPoints(const QPointF *points, int pointCount)
         return;
     }
 
-    static const int BUF_SIZE = 1024;
-    XPoint xPoints[BUF_SIZE];
+    XPoint xPoints[pointCount];
     int i = 0, j = 0;
     while (i < pointCount) {
-        while (i < pointCount && j < BUF_SIZE) {
-            const QPointF &xformed = d->matrix.map(points[i]);
-            int x = qFloor(xformed.x());
-            int y = qFloor(xformed.y());
-
-            if (x >= SHRT_MIN && y >= SHRT_MIN && x < SHRT_MAX && y < SHRT_MAX) {
-                xPoints[j].x = x;
-                xPoints[j].y = y;
-                ++j;
-            }
-            ++i;
+        const QPointF &xformed = d->matrix.map(points[i]);
+        int x = qFloor(xformed.x());
+        int y = qFloor(xformed.y());
+
+        if (x >= SHRT_MIN && y >= SHRT_MIN && x < SHRT_MAX && y < SHRT_MAX) {
+            xPoints[j].x = x;
+            xPoints[j].y = y;
+            ++j;
         }
-        if (j)
-            XDrawPoints(d->dpy, d->hd, d->gc, xPoints, j, CoordModeOrigin);
-
-        j = 0;
+        ++i;
     }
+    XDrawPoints(d->dpy, d->hd, d->gc, xPoints, j, CoordModeOrigin);
 }
 
 QPainter::RenderHints QX11PaintEngine::supportedRenderHints() const