summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-12-03 21:53:43 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-12-03 21:53:43 (GMT)
commit83162e22f9b4d59f7bcf9c2625a627aa7b8a0d03 (patch)
tree502a6d4934ba2b0eb4930fc541643f8c9cf04d50
parent8e645502b87e972499ec6fe5662ec499c082029c (diff)
downloadQt-83162e22f9b4d59f7bcf9c2625a627aa7b8a0d03.zip
Qt-83162e22f9b4d59f7bcf9c2625a627aa7b8a0d03.tar.gz
Qt-83162e22f9b4d59f7bcf9c2625a627aa7b8a0d03.tar.bz2
Minor optimization of image lookup from cache.
-rw-r--r--src/declarative/util/qmlpixmapcache.cpp70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/declarative/util/qmlpixmapcache.cpp b/src/declarative/util/qmlpixmapcache.cpp
index d4143e8..9509595 100644
--- a/src/declarative/util/qmlpixmapcache.cpp
+++ b/src/declarative/util/qmlpixmapcache.cpp
@@ -147,59 +147,62 @@ bool QmlPixmapCache::find(const QUrl& url, QPixmap *pixmap)
QmlPerfTimer<QmlPerf::PixmapLoad> perf;
#endif
- QString key = url.toString();
bool ok = true;
- if (!QPixmapCache::find(key,pixmap)) {
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- QString lf = toLocalFileOrQrc(url);
- if (!lf.isEmpty()) {
+ QString lf = toLocalFileOrQrc(url);
+ if (!lf.isEmpty()) {
+ if (!QPixmapCache::find(lf,pixmap)) {
QFile f(lf);
if (f.open(QIODevice::ReadOnly)) {
if (!readImage(&f, pixmap)) {
qWarning() << "Format error loading" << url;
*pixmap = QPixmap();
ok = false;
+ } else {
+ QPixmapCache::insert(lf, *pixmap);
+ ok = !pixmap->isNull();
}
} else {
*pixmap = QPixmap();
ok = false;
}
- } else
+ } else {
+ ok = !pixmap->isNull();
+ }
+ return ok;
+ }
#endif
- {
- QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key);
- if (iter == qfxActiveNetworkReplies.end()) {
- // API usage error
- qWarning() << "QmlPixmapCache: URL not loaded" << url;
+
+ QString key = url.toString();
+ if (!QPixmapCache::find(key,pixmap)) {
+ QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key);
+ if (iter == qfxActiveNetworkReplies.end()) {
+ // API usage error
+ qWarning() << "QmlPixmapCache: URL not loaded" << url;
+ ok = false;
+ } else {
+ if ((*iter)->reply->error()) {
+ qWarning() << "Network error loading" << url << (*iter)->reply->errorString();
+ *pixmap = QPixmap();
+ ok = false;
+ } else if (!readImage((*iter)->reply, pixmap)) {
+ qWarning() << "Format error loading" << url;
+ *pixmap = QPixmap();
ok = false;
} else {
- if ((*iter)->reply->error()) {
- qWarning() << "Network error loading" << url << (*iter)->reply->errorString();
- *pixmap = QPixmap();
- ok = false;
- } else if (!readImage((*iter)->reply, pixmap)) {
- qWarning() << "Format error loading" << url;
- *pixmap = QPixmap();
- ok = false;
- } else {
- if ((*iter)->refCount > 1)
- (*iter)->pixmap = *pixmap;
- }
- (*iter)->release();
+ if ((*iter)->refCount > 1)
+ (*iter)->pixmap = *pixmap;
}
+ (*iter)->release();
}
QPixmapCache::insert(key, *pixmap);
} else {
ok = !pixmap->isNull();
-#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- if (url.scheme()!=QLatin1String("file"))
-#endif
+
// We may be the second finder. Still need to check for active replies.
- {
- QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key);
- if (iter != qfxActiveNetworkReplies.end())
- (*iter)->release();
- }
+ QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key);
+ if (iter != qfxActiveNetworkReplies.end())
+ (*iter)->release();
}
return ok;
}
@@ -223,8 +226,7 @@ QNetworkReply *QmlPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
QString lf = toLocalFileOrQrc(url);
if (!lf.isEmpty()) {
- QString key = url.toString();
- if (!QPixmapCache::find(key,pixmap)) {
+ if (!QPixmapCache::find(lf,pixmap)) {
bool loaded = true;
QFile f(lf);
if (f.open(QIODevice::ReadOnly)) {
@@ -239,7 +241,7 @@ QNetworkReply *QmlPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *
loaded = false;
}
if (loaded)
- QPixmapCache::insert(key, *pixmap);
+ QPixmapCache::insert(lf, *pixmap);
if (ok) *ok = loaded;
}
return 0;