OSDN Git Service

optimize polygons build-up by reserving space for the points
authorIvailo Monev <xakepa10@gmail.com>
Thu, 16 Jun 2022 02:15:41 +0000 (05:15 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Thu, 16 Jun 2022 02:15:41 +0000 (05:15 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/designer/shared/connectionedit.cpp
src/gui/painting/qcssutil.cpp
src/gui/painting/qpainterpath.cpp

index 128a92b..97cf792 100644 (file)
@@ -350,7 +350,6 @@ QPoint Connection::endPointPos(EndPoint::Type type) const
 static QPoint lineEntryPos(const QPoint &p1, const QPoint &p2, const QRect &rect)
 {
     QPoint result;
-
     switch (classifyLine(p1, p2)) {
         case CETypes::UpDir:
             result = QPoint(p1.x(), rect.bottom());
@@ -365,14 +364,13 @@ static QPoint lineEntryPos(const QPoint &p1, const QPoint &p2, const QRect &rect
             result = QPoint(rect.left(), p1.y());
             break;
     }
-
     return result;
 }
 
 static QPolygonF arrowHead(const QPoint &p1, const QPoint &p2)
 {
     QPolygonF result;
-
+    result.reserve(3);
     switch (classifyLine(p1, p2)) {
         case CETypes::UpDir:
             result.append(p2 + QPoint(0, 1));
@@ -395,7 +393,6 @@ static QPolygonF arrowHead(const QPoint &p1, const QPoint &p2)
             result.append(p2 + QPoint(-2*LINE_PROXIMITY_RADIUS, LINE_PROXIMITY_RADIUS));
             break;
     }
-
     return result;
 }
 
index 7042db8..36496b3 100644 (file)
@@ -188,6 +188,7 @@ void qDrawEdge(QPainter *p, qreal x1, qreal y1, qreal x2, qreal y2, qreal dw1, q
             p->drawRect(QRectF(x1, y1, x2-x1, y2-y1));
         } else { // draw trapezoid
             QPolygonF quad;
+            quad.reserve(4);
             switch (edge) {
             case TopEdge:
                 quad << QPointF(x1, y1) << QPointF(x1 + dw1, y2)
index aac9121..f7e2e30 100644 (file)
@@ -1607,6 +1607,7 @@ QList<QPolygonF> QPainterPath::toFillPolygons(const QTransform &matrix) const
         const QList<int> &subpath_list = isects[i];
         if (!subpath_list.isEmpty()) {
             QPolygonF buildUp;
+            buildUp.reserve(subpath_list.size());
             for (int j=0; j<subpath_list.size(); ++j) {
                 const QPolygonF &subpath = subpaths.at(subpath_list.at(j));
                 buildUp += subpath;
@@ -2664,6 +2665,7 @@ QPolygonF QPainterPath::toFillPolygon(const QTransform &matrix) const
     if (flats.isEmpty())
         return polygon;
     QPointF first = flats.first().first();
+    polygon.reserve(flats.size());
     for (int i=0; i<flats.size(); ++i) {
         polygon += flats.at(i);
         if (!flats.at(i).isClosed())