From 30836b8ba96bf20d378009e08895aa7b22501363 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Wed, 4 Dec 2024 03:13:53 +0100 Subject: [PATCH] Small welcome panel optimisation --- Source/Components/WelcomePanel.h | 11 ++++++++++- Source/Pd/Library.cpp | 5 +---- Source/Utility/OSUtils.cpp | 5 +++++ Source/Utility/OSUtils.h | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Source/Components/WelcomePanel.h b/Source/Components/WelcomePanel.h index f86e18a02..4a4fb91d3 100644 --- a/Source/Components/WelcomePanel.h +++ b/Source/Components/WelcomePanel.h @@ -804,7 +804,15 @@ class WelcomePanel : public Component } if (thumbImage.isNull()) { if (patchFile.existsAsFile()) { - silhoutteSvg = OfflineObjectRenderer::patchToSVG(patchFile.loadFileAsString()); + auto cachedSilhouette = patchSvgCache.find(patchFile.getFullPathName()); + if(cachedSilhouette != patchSvgCache.end()) + { + silhoutteSvg = cachedSilhouette->second; + } + else { + silhoutteSvg = OfflineObjectRenderer::patchToSVG(patchFile.loadFileAsString()); + patchSvgCache[patchFile.getFullPathName()] = silhoutteSvg; + } } } @@ -949,6 +957,7 @@ class WelcomePanel : public Component String searchQuery; Tab currentTab = Home; + UnorderedMap patchSvgCache; // To make the library panel update automatically class LibraryFSListener : public FileSystemWatcher::Listener diff --git a/Source/Pd/Library.cpp b/Source/Pd/Library.cpp index 693fd7b86..d26ada38a 100644 --- a/Source/Pd/Library.cpp +++ b/Source/Pd/Library.cpp @@ -345,11 +345,8 @@ File Library::findFile(String const& fileToFind) auto pathTree = SettingsFile::getInstance()->getValueTree().getChildWithName("Paths"); for (auto path : pathTree) { auto searchPath = File(path.getProperty("Path").toString()); - if (!searchPath.exists() || !searchPath.isDirectory()) - continue; - auto childFile = searchPath.getChildFile(fileToFind); - if (childFile.existsAsFile()) + if (OSUtils::isFileFast(childFile.getFullPathName())) return childFile; } diff --git a/Source/Utility/OSUtils.cpp b/Source/Utility/OSUtils.cpp index ba2c6bd1b..dde841405 100644 --- a/Source/Utility/OSUtils.cpp +++ b/Source/Utility/OSUtils.cpp @@ -307,6 +307,11 @@ bool OSUtils::isDirectoryFast(juce::String const& path) return fs::is_directory(path.toStdString()); } +bool OSUtils::isFileFast(juce::String const& path) +{ + return fs::is_regular_file(path.toStdString()); +} + hash32 OSUtils::getUniqueFileHash(juce::String const& path) { return hash(fs::canonical(path.toStdString()).c_str()); diff --git a/Source/Utility/OSUtils.h b/Source/Utility/OSUtils.h index b67286ead..8c047eae1 100644 --- a/Source/Utility/OSUtils.h +++ b/Source/Utility/OSUtils.h @@ -40,6 +40,7 @@ struct OSUtils { static SmallArray iterateDirectory(juce::File const& directory, bool recursive, bool onlyFiles, int maximum = -1); static bool isDirectoryFast(juce::String const& path); + static bool isFileFast(juce::String const& path); static hash32 getUniqueFileHash(juce::String const& path); static KeyboardLayout getKeyboardLayout();