From cc2b991e78662f4b5fdd30895d26fc2d17f40f3e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 5 Aug 2017 08:45:37 +0300 Subject: [PATCH] Performance optimization. --HG-- branch : develop --- src/libs/vlayout/vabstractpiece.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index dea8832d8..dade08f8a 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -267,11 +267,22 @@ QVector VAbstractPiece::CheckLoops(const QVector &points) continue; } - QSet uniqueVertices; - uniqueVertices << i << i+1 << j; + QVector uniqueVertices; + + auto AddUniqueIndex = [&uniqueVertices](qint32 i) + { + if (not uniqueVertices.contains(i)) + { + uniqueVertices.append(i); + } + }; + + AddUniqueIndex(i); + AddUniqueIndex(i+1); + AddUniqueIndex(j); // For closed path last point is equal to first. Using index of the first. - pathClosed && jNext == count-1 ? uniqueVertices << 0 : uniqueVertices << jNext; + pathClosed && jNext == count-1 ? AddUniqueIndex(0) : AddUniqueIndex(jNext); const QLineF::IntersectType intersect = line1.intersect(line2, &crosPoint); if (intersect == QLineF::NoIntersection)