From 97965a0908b8fbf7f01d0880410929a4ea61b48d Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 24 Feb 2016 15:53:59 +0300 Subject: QtGui: use reserve to optimize memory allocation. Change-Id: I34a571b67840557de19ab496cadebd698c7f4f6a Reviewed-by: Marc Mutz --- src/gui/kernel/qhighdpiscaling_p.h | 2 ++ src/gui/kernel/qwindowsysteminterface.cpp | 2 +- src/gui/text/qfontsubset.cpp | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index 60e8dcf562..fe71de6c27 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -473,6 +473,7 @@ QVector fromNativePixels(const QVector &pixelValues, const QWindow *window return pixelValues; QVector pointValues; + pointValues.reserve(pixelValues.size()); for (const T &pixelValue : pixelValues) pointValues.append(pixelValue / QHighDpiScaling::factor(window)); return pointValues; @@ -486,6 +487,7 @@ QVector toNativePixels(const QVector &pointValues, const QWindow *window) return pointValues; QVector pixelValues; + pixelValues.reserve(pointValues.size()); for (const T &pointValue : pointValues) pixelValues.append(pointValue * QHighDpiScaling::factor(window)); return pixelValues; diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index c76721f89b..39bc161a7c 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -928,7 +928,7 @@ static QWindowSystemInterface::TouchPoint touchPoint(const QTouchEvent::TouchPoi static QList touchPointList(const QList& pointList) { QList newList; - + newList.reserve(pointList.size()); for (const QTouchEvent::TouchPoint &p : pointList) newList.append(touchPoint(p)); diff --git a/src/gui/text/qfontsubset.cpp b/src/gui/text/qfontsubset.cpp index 34db39e4a8..a9387e5aa0 100644 --- a/src/gui/text/qfontsubset.cpp +++ b/src/gui/text/qfontsubset.cpp @@ -624,6 +624,7 @@ static QTtfTable generateName(const QVector &name); static QTtfTable generateName(const qttf_name_table &name) { QVector list; + list.reserve(5); QTtfNameRecord rec; rec.nameId = 0; rec.value = name.copyright; @@ -1061,6 +1062,7 @@ static QVector generateGlyphTables(qttf_font_tables &tables, const QV Q_ASSERT(hmtx.data.size() == hs.offset()); QVector list; + list.reserve(3); list.append(glyf); list.append(loca); list.append(hmtx); -- cgit v1.2.3