From d1b099c3e3cfcbf86353b53e205c0ebf84cf5592 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 14 Aug 2019 09:41:18 +0200 Subject: QBezier: replace out parameters by return-by-value in split() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At least QBezier itself is calling the old function with *this aliased to one of the arguments. Consequently, the implementation looks rather ... shuffled, to avoid writing into members that it will read once more later. Fix by returning a std::pair instead. This simplifies the code that doesn't actually pass existing objects in, and avoids aliasing problems cropping up under seemingly innocuous reorderings of statements in the implementation going forward. While I'm usually vehemently against use std::pair or std::tuple in APIs, preferring simple structs with aptly-named members instead, this is one case where the .first and .second actually fit, and pair allows us to use std::tie, which was handy in qbezier.cpp. This patch preserves the body of the function as much as possible. A follow-up patch will clean it up. Change-Id: I017dfee4a0e69a2e171ce21b89ba04654772c33d Reviewed-by: Edward Welbourne Reviewed-by: MÃ¥rten Nordheim --- src/gui/painting/qbezier.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gui/painting/qbezier.cpp') diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp index daf19fffe1..9861fffff3 100644 --- a/src/gui/painting/qbezier.cpp +++ b/src/gui/painting/qbezier.cpp @@ -47,6 +47,8 @@ #include +#include // for std::tie() + QT_BEGIN_NAMESPACE //#define QDEBUG_BEZIER @@ -128,7 +130,7 @@ void QBezier::addToPolygon(QPolygonF *polygon, qreal bezier_flattening_threshold --lvl; } else { // split, second half of the polygon goes lower into the stack - b->split(b+1, b); + std::tie(b[1], b[0]) = b->split(); lvl[1] = --lvl[0]; ++b; ++lvl; @@ -166,7 +168,7 @@ void QBezier::addToPolygon(QDataBuffer &polygon, qreal bezier_flattenin --lvl; } else { // split, second half of the polygon goes lower into the stack - b->split(b+1, b); + std::tie(b[1], b[0]) = b->split(); lvl[1] = --lvl[0]; ++b; ++lvl; @@ -422,7 +424,7 @@ redo: o += 2; --b; } else { - b->split(b+1, b); + std::tie(b[1], b[0]) = b->split(); ++b; } } @@ -464,8 +466,6 @@ qreal QBezier::length(qreal error) const void QBezier::addIfClose(qreal *length, qreal error) const { - QBezier left, right; /* bez poly splits */ - qreal len = qreal(0.0); /* arc length */ qreal chord; /* chord length */ @@ -476,9 +476,9 @@ void QBezier::addIfClose(qreal *length, qreal error) const chord = QLineF(QPointF(x1, y1),QPointF(x4, y4)).length(); if((len-chord) > error) { - split(&left, &right); /* split in two */ - left.addIfClose(length, error); /* try left side */ - right.addIfClose(length, error); /* try right side */ + const auto halves = split(); /* split in two */ + halves.first.addIfClose(length, error); /* try left side */ + halves.second.addIfClose(length, error); /* try right side */ return; } -- cgit v1.2.3