From 188cfb0ad684f21f90ca11cdba1845c4fa97353a Mon Sep 17 00:00:00 2001 From: Tomi Korpipaa Date: Fri, 25 Sep 2020 08:09:12 +0300 Subject: Prevent duplicates in searchPaths and reverse it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first 3 paths in the searchPaths are for finding the other things we need to search for, the last ones are for source paths. Reversing the order drops the required search count in a usual case from 4 attempts to 1 or 2. Task-number: QT3DS-4172 Change-Id: I0d7665566be6b8a9d5e7b918f7596f70126ad958 Reviewed-by: Antti Määttä Reviewed-by: Janne Koskinen --- src/runtime/Qt3DSApplication.cpp | 7 ++++--- src/runtimerender/resourcemanager/Qt3DSRenderBufferManager.cpp | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/runtime/Qt3DSApplication.cpp b/src/runtime/Qt3DSApplication.cpp index 5c6dbb7..db5d359 100644 --- a/src/runtime/Qt3DSApplication.cpp +++ b/src/runtime/Qt3DSApplication.cpp @@ -2267,9 +2267,10 @@ bool AssetHandlers::handlePresentation(SApp &app, SAssetValue &asset, bool initI CFileTools::CombineBaseAndRelative(app.GetProjectDirectory().c_str(), asset.GetSource(), thePathStr); - QDir::addSearchPath(QStringLiteral("qt3dstudio"), - QFileInfo(QString(thePathStr.c_str())) - .absoluteDir().absolutePath()); + const QString absPath = QFileInfo(QString(thePathStr.c_str())).absoluteDir().absolutePath(); + if (!QDir::searchPaths(QStringLiteral("qt3dstudio")).contains(absPath)) + QDir::addSearchPath(QStringLiteral("qt3dstudio"), absPath); + SPresentationAsset &thePresentationAsset = *asset.getDataPtr(); eastl::vector theUIPReferences; diff --git a/src/runtimerender/resourcemanager/Qt3DSRenderBufferManager.cpp b/src/runtimerender/resourcemanager/Qt3DSRenderBufferManager.cpp index 87fe54c..6a0fdff 100644 --- a/src/runtimerender/resourcemanager/Qt3DSRenderBufferManager.cpp +++ b/src/runtimerender/resourcemanager/Qt3DSRenderBufferManager.cpp @@ -61,12 +61,14 @@ static const QString QT3DSTUDIO_TAG = QStringLiteral("qt3dstudio"); static QFileInfo matchCaseInsensitiveFile(const QString& file) { - const auto searchFromPaths = [](QString file) -> QFileInfo { + QStringList searchDirectories = QDir::searchPaths(QT3DSTUDIO_TAG); + std::reverse(searchDirectories.begin(), searchDirectories.end()); + + const auto searchFromPaths = [searchDirectories](QString file) -> QFileInfo { QFileInfo fileInfo(file); if (fileInfo.exists()) return fileInfo; - const QStringList searchDirectories = QDir::searchPaths(QT3DSTUDIO_TAG); for (const auto &directoryPath : searchDirectories) { auto path = QDir::cleanPath(directoryPath + '/' + file); QFileInfo info(path); @@ -203,6 +205,7 @@ QString IBufferManager::resolveImagePath(const QString &sourcePath, bool preferK } // First check ktx files if preferKtx is set + QString result; if (preferKtx) { QString ktxSource = path; const bool originalIsKtx = path.endsWith(QLatin1String("ktx"), Qt::CaseInsensitive); @@ -211,7 +214,6 @@ QString IBufferManager::resolveImagePath(const QString &sourcePath, bool preferK ktxSource = ktxSource.left(index); ktxSource.append(QLatin1String(".ktx")); } - QString result; if (checkFileExists(ktxSource, relative, result)) return result; if (originalIsKtx) { @@ -220,7 +222,6 @@ QString IBufferManager::resolveImagePath(const QString &sourcePath, bool preferK } } - QString result; if (checkFileExists(path, relative, result)) return result; -- cgit v1.2.3