Skip to content

Commit

Permalink
Small welcome panel optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Dec 4, 2024
1 parent fc21731 commit 30836b8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Source/Components/WelcomePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -949,6 +957,7 @@ class WelcomePanel : public Component

String searchQuery;
Tab currentTab = Home;
UnorderedMap<String, String> patchSvgCache;

// To make the library panel update automatically
class LibraryFSListener : public FileSystemWatcher::Listener
Expand Down
5 changes: 1 addition & 4 deletions Source/Pd/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions Source/Utility/OSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions Source/Utility/OSUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct OSUtils {

static SmallArray<juce::File> 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();
Expand Down

0 comments on commit 30836b8

Please sign in to comment.