From 96f4394dce60c58537035ca5d6f903fa88a637eb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 26 Feb 2016 15:00:41 +0100 Subject: db/update/Archive: pass ArchiveFile to Song constructor Don't open the ZIP file again and again for each song file. --- src/db/update/Archive.cxx | 17 ++++++++++------- src/db/update/Walk.hxx | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/db/update/Archive.cxx b/src/db/update/Archive.cxx index 160163987..df7bb2c1c 100644 --- a/src/db/update/Archive.cxx +++ b/src/db/update/Archive.cxx @@ -61,7 +61,8 @@ LockFindSong(Directory &directory, const char *name) } void -UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name) +UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory, + const char *name) { const char *tmp = strchr(name, '/'); if (tmp) { @@ -72,7 +73,7 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name) subdir->device = DEVICE_INARCHIVE; //create directories first - UpdateArchiveTree(*subdir, tmp + 1); + UpdateArchiveTree(archive, *subdir, tmp + 1); } else { if (StringIsEmpty(name)) { LogWarning(update_domain, @@ -83,7 +84,7 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name) //add file Song *song = LockFindSong(directory, name); if (song == nullptr) { - song = Song::LoadFile(storage, name, directory); + song = Song::LoadFromArchive(archive, name, directory); if (song != nullptr) { { const ScopeDatabaseLock protect; @@ -100,16 +101,18 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name) class UpdateArchiveVisitor final : public ArchiveVisitor { UpdateWalk &walk; + ArchiveFile &archive; Directory *directory; public: - UpdateArchiveVisitor(UpdateWalk &_walk, Directory *_directory) - :walk(_walk), directory(_directory) {} + UpdateArchiveVisitor(UpdateWalk &_walk, ArchiveFile &_archive, + Directory *_directory) + :walk(_walk), archive(_archive), directory(_directory) {} virtual void VisitArchiveEntry(const char *path_utf8) override { FormatDebug(update_domain, "adding archive file: %s", path_utf8); - walk.UpdateArchiveTree(*directory, path_utf8); + walk.UpdateArchiveTree(archive, *directory, path_utf8); } }; @@ -165,7 +168,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name, directory->mtime = info.mtime; - UpdateArchiveVisitor visitor(*this, directory); + UpdateArchiveVisitor visitor(*this, *file, directory); file->Visit(visitor); file->Close(); } diff --git a/src/db/update/Walk.hxx b/src/db/update/Walk.hxx index 99d54ef51..b4b5fba5f 100644 --- a/src/db/update/Walk.hxx +++ b/src/db/update/Walk.hxx @@ -30,6 +30,7 @@ struct stat; struct StorageFileInfo; struct Directory; struct ArchivePlugin; +class ArchiveFile; class Storage; class ExcludeList; @@ -101,7 +102,8 @@ private: #ifdef ENABLE_ARCHIVE - void UpdateArchiveTree(Directory &parent, const char *name); + void UpdateArchiveTree(ArchiveFile &archive, Directory &parent, + const char *name); bool UpdateArchiveFile(Directory &directory, const char *name, const char *suffix, -- cgit v1.2.3