QPolygon: de-inline setPoint()

In Qt 5 times, the core of QList::realloc() was out-of-line by design,
because it was independent of T.

Now that QList is QVector, its equivalent detachAndGrow() function on
QArrayDataPointer is inline and instantiated for each type anew. We
therefore need to be careful to not use detach()ing QList operations
in non-generic code inline code (in public, but also private,
headers), because (common) PCH builds force this code to be compiled
over and over again. Generic code is only instantiated when used in a
TU, so that's ok. But for non-generic code, the only option is to
de-inline.

If there is an effect on compile-times, it's hidden in the run-by-run
noise of building QtGui, but at least this entry is gone afterwards
from clang -ftime-trace:

  **** Templates that took longest to instantiate:
  [...]
    4676 ms: QList<QPoint>::operator[] (261 times, avg 17 ms)

Added 'inline' to the definition of the setPoint(int, QPoint)
overload, since MinGW used to complain about it missing.

Task-number: QTBUG-97601
Pick-to: 6.3
Change-Id: Ie6f67da7ef39a16c98a7451d37b6d96531656392
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Marc Mutz 2022-01-14 11:23:31 +01:00
parent 49e263ef4b
commit f7ac5968fc
2 changed files with 8 additions and 8 deletions

View File

@ -263,13 +263,16 @@ void QPolygon::point(int index, int *x, int *y) const
*/
/*!
\fn void QPolygon::setPoint(int index, int x, int y)
Sets the point at the given \a index to the point specified by
(\a{x}, \a{y}).
\sa point(), putPoints(), setPoints(),
*/
void QPolygon::setPoint(int index, int x, int y)
{
(*this)[index] = QPoint(x, y);
}
/*!
Resizes the polygon to \a nPoints and populates it with the given

View File

@ -76,8 +76,8 @@ public:
Q_GUI_EXPORT void point(int i, int *x, int *y) const;
QPoint point(int i) const;
void setPoint(int index, int x, int y);
void setPoint(int index, const QPoint &p);
Q_GUI_EXPORT void setPoint(int index, int x, int y);
inline void setPoint(int index, const QPoint &p);
Q_GUI_EXPORT void setPoints(int nPoints, const int *points);
Q_GUI_EXPORT void setPoints(int nPoints, int firstx, int firsty, ...);
Q_GUI_EXPORT void putPoints(int index, int nPoints, const int *points);
@ -111,10 +111,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
*****************************************************************************/
inline void QPolygon::setPoint(int index, const QPoint &pt)
{ (*this)[index] = pt; }
inline void QPolygon::setPoint(int index, int x, int y)
{ (*this)[index] = QPoint(x, y); }
{ setPoint(index, pt.x(), pt.y()); }
inline QPoint QPolygon::point(int index) const
{ return at(index); }