diff options
author | Sérgio Martins <sergio.martins@kdab.com> | 2016-01-16 00:24:54 +0000 |
---|---|---|
committer | Sérgio Martins <iamsergio@gmail.com> | 2016-02-07 16:50:26 +0000 |
commit | 01859cc12126b7205f5b54d383a9aa88db756f21 (patch) | |
tree | 89ea0594e2d6e86bc1e0e271d9bf4215a387b28e /src/gui/painting/qpdf.cpp | |
parent | af499fd7eb4026088ea1ed83a976866ab930dd79 (diff) |
Reduce allocations by using reserve()
Change-Id: If34fa53402985f6b3c5e7217bce4a1177af835b6
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/gui/painting/qpdf.cpp')
-rw-r--r-- | src/gui/painting/qpdf.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index d746ab9379..d68d719c39 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1003,7 +1003,8 @@ void QPdfEngine::drawHyperlink(const QRectF &r, const QUrl &url) const uint annot = d->addXrefEntry(-1); const QByteArray urlascii = url.toEncoded(); int len = urlascii.size(); - QVarLengthArray<char> url_esc(0); + QVarLengthArray<char> url_esc; + url_esc.reserve(len + 1); for (int j = 0; j < len; j++) { if (urlascii[j] == '(' || urlascii[j] == ')' || urlascii[j] == '\\') url_esc.append('\\'); @@ -2007,10 +2008,11 @@ int QPdfEnginePrivate::createShadingFunction(const QGradient *gradient, int from } QVector<QGradientBound> gradientBounds; + gradientBounds.reserve((to - from) * (numStops - 1)); for (int step = from; step < to; ++step) { if (reflect && step % 2) { - for (int i = stops.size() - 1; i > 0; --i) { + for (int i = numStops - 1; i > 0; --i) { QGradientBound b; b.start = step + 1 - qBound(qreal(0.), stops.at(i).first, qreal(1.)); b.stop = step + 1 - qBound(qreal(0.), stops.at(i - 1).first, qreal(1.)); @@ -2019,7 +2021,7 @@ int QPdfEnginePrivate::createShadingFunction(const QGradient *gradient, int from gradientBounds << b; } } else { - for (int i = 0; i < stops.size() - 1; ++i) { + for (int i = 0; i < numStops - 1; ++i) { QGradientBound b; b.start = step + qBound(qreal(0.), stops.at(i).first, qreal(1.)); b.stop = step + qBound(qreal(0.), stops.at(i + 1).first, qreal(1.)); |