aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickimagebase.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@viroteck.net>2015-06-05 12:12:11 +0300
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-09 04:45:42 +0000
commit834f9c76151857b8e8bc07341f592187fafa11dc (patch)
tree365056886982d0cb20026d64cab46dfc928aa053 /src/quick/items/qquickimagebase.cpp
parent52d91eeea4f49d36c18efd39e12f2634992cb63b (diff)
QQuickImageBase: Minimize the cost for devicePixelRatio setting.
* Don't convert QUrl to QString twice (that massively blows up transient allocations and is very slow) * Don't do anything at all if a sourceSize isn't set (checking it is super cheap) This fixes the performance regression (introduced in 428b92583ee2102c7ef16776a9b7785df7ff4e2c) in the delegates_image creation benchmark (from ~520 up to ~540 items per frame). Change-Id: I1cd350e42e763b7a771ff207d23e3e411810b268 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/quick/items/qquickimagebase.cpp')
-rw-r--r--src/quick/items/qquickimagebase.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp
index 0e2134842b..a1930e6623 100644
--- a/src/quick/items/qquickimagebase.cpp
+++ b/src/quick/items/qquickimagebase.cpp
@@ -213,15 +213,27 @@ void QQuickImageBase::load()
d->devicePixelRatio = 1.0;
QUrl loadUrl = d->url;
- if (d->url.scheme() == QStringLiteral("image")
- || d->url.toString().endsWith(QLatin1String(".svg"))
- || d->url.toString().endsWith(QLatin1String(".svgz"))) {
- // QQuickImageProvider and SVG can generate a high resolution image when
- // sourceSize is set. If sourceSize is not set then the provider default size
- // will be used, as usual.
- if (!d->sourcesize.isEmpty())
+
+ // QQuickImageProvider and SVG can generate a high resolution image when
+ // sourceSize is set. If sourceSize is not set then the provider default size
+ // will be used, as usual.
+ bool setDevicePixelRatio = false;
+ if (!d->sourcesize.isValid()) {
+ if (loadUrl.scheme() == QStringLiteral("image")) {
+ setDevicePixelRatio = true;
+ } else {
+ QString stringUrl = loadUrl.toString();
+ if (stringUrl.endsWith(QLatin1String("svg")) ||
+ stringUrl.endsWith(QLatin1String("svgz"))) {
+ setDevicePixelRatio = true;
+ }
+ }
+
+ if (setDevicePixelRatio)
d->devicePixelRatio = targetDevicePixelRatio;
- } else {
+ }
+
+ if (!setDevicePixelRatio) {
// (possible) local file: loadUrl and d->devicePixelRatio will be modified if
// an "@2x" file is found.
resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);