From a826569a0f55066746ea6fa72be8c32b5b785180 Mon Sep 17 00:00:00 2001 From: Zach Nelson Date: Wed, 4 Mar 2026 19:48:02 -0600 Subject: [PATCH] refactor: Avoid rebuilding cache path strings (#1300) ## Summary **What is the goal of this PR?** Avoid building cache path strings twice, once to check existence of the file and a second time to delete the file. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**NO**_ --- lib/Epub/Epub/BookMetadataCache.cpp | 10 ++++++---- lib/Epub/Epub/parsers/ContentOpfParser.cpp | 8 +++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Epub/Epub/BookMetadataCache.cpp b/lib/Epub/Epub/BookMetadataCache.cpp index 236c6b17..3cdee0b0 100644 --- a/lib/Epub/Epub/BookMetadataCache.cpp +++ b/lib/Epub/Epub/BookMetadataCache.cpp @@ -274,11 +274,13 @@ bool BookMetadataCache::buildBookBin(const std::string& epubPath, const BookMeta } bool BookMetadataCache::cleanupTmpFiles() const { - if (Storage.exists((cachePath + tmpSpineBinFile).c_str())) { - Storage.remove((cachePath + tmpSpineBinFile).c_str()); + const auto spineBinFile = cachePath + tmpSpineBinFile; + if (Storage.exists(spineBinFile.c_str())) { + Storage.remove(spineBinFile.c_str()); } - if (Storage.exists((cachePath + tmpTocBinFile).c_str())) { - Storage.remove((cachePath + tmpTocBinFile).c_str()); + const auto tocBinFile = cachePath + tmpTocBinFile; + if (Storage.exists(tocBinFile.c_str())) { + Storage.remove(tocBinFile.c_str()); } return true; } diff --git a/lib/Epub/Epub/parsers/ContentOpfParser.cpp b/lib/Epub/Epub/parsers/ContentOpfParser.cpp index 1cf7e7e0..33518bc6 100644 --- a/lib/Epub/Epub/parsers/ContentOpfParser.cpp +++ b/lib/Epub/Epub/parsers/ContentOpfParser.cpp @@ -36,12 +36,10 @@ ContentOpfParser::~ContentOpfParser() { if (tempItemStore) { tempItemStore.close(); } - if (Storage.exists((cachePath + itemCacheFile).c_str())) { - Storage.remove((cachePath + itemCacheFile).c_str()); + const auto itemCachePath = cachePath + itemCacheFile; + if (Storage.exists(itemCachePath.c_str())) { + Storage.remove(itemCachePath.c_str()); } - itemIndex.clear(); - itemIndex.shrink_to_fit(); - useItemIndex = false; } size_t ContentOpfParser::write(const uint8_t data) { return write(&data, 1); }