From 52c12b0c2f44fbff613d11d30a8f3b710b73a5fc Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 20 Apr 2022 10:58:30 +0200 Subject: [PATCH] Introduce `Library::Impl::getBookCount` We simply introduce a `getBookCount` which is not protected by a lock. --- src/library.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 95a3dbf03..c5b68a40a 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -75,6 +75,8 @@ struct Library::Impl std::vector m_bookmarks; Xapian::WritableDatabase m_bookDB; + unsigned int getBookCount(const bool localBooks, const bool remoteBooks) const; + Impl(); ~Impl(); @@ -94,7 +96,19 @@ Library::Impl::~Impl() Library::Impl::Impl(Library::Impl&& ) = default; Library::Impl& Library::Impl::operator=(Library::Impl&& ) = default; - +unsigned int +Library::Impl::getBookCount(const bool localBooks, const bool remoteBooks) const +{ + unsigned int result = 0; + for (auto& pair: m_books) { + auto& book = pair.second; + if ((!book.getPath().empty() && localBooks) + || (book.getPath().empty() && remoteBooks)) { + result++; + } + } + return result; +} /* Constructor */ Library::Library() @@ -263,15 +277,7 @@ unsigned int Library::getBookCount(const bool localBooks, const bool remoteBooks) const { std::lock_guard lock(m_mutex); - unsigned int result = 0; - for (auto& pair: mp_impl->m_books) { - auto& book = pair.second; - if ((!book.getPath().empty() && localBooks) - || (book.getPath().empty() && remoteBooks)) { - result++; - } - } - return result; + return mp_impl->getBookCount(localBooks, remoteBooks); } bool Library::writeToFile(const std::string& path) const