refactor: consolidate Epub blank strings, simplify BookInfo buildLayout
Replace 13 per-accessor static std::string blank locals with a single file-scope kBlank (~384 bytes DRAM saved). Add Epub::getMetadata() returning the full BookMetadata struct. Refactor buildLayout from 14 individual parameters to a single BookMetadata const ref + fileSize. Made-with: Cursor
This commit is contained in:
@@ -13,6 +13,11 @@
|
||||
#include "Epub/parsers/TocNavParser.h"
|
||||
#include "Epub/parsers/TocNcxParser.h"
|
||||
|
||||
namespace {
|
||||
const std::string kBlank;
|
||||
const BookMetadataCache::BookMetadata kBlankMetadata;
|
||||
} // namespace
|
||||
|
||||
bool Epub::findContentOpfFile(std::string* contentOpfFile) const {
|
||||
const auto containerPath = "META-INF/container.xml";
|
||||
size_t containerSize;
|
||||
@@ -501,101 +506,75 @@ const std::string& Epub::getCachePath() const { return cachePath; }
|
||||
const std::string& Epub::getPath() const { return filepath; }
|
||||
|
||||
const std::string& Epub::getTitle() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) {
|
||||
return blank;
|
||||
}
|
||||
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.title;
|
||||
}
|
||||
|
||||
const std::string& Epub::getAuthor() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) {
|
||||
return blank;
|
||||
}
|
||||
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.author;
|
||||
}
|
||||
|
||||
const std::string& Epub::getLanguage() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) {
|
||||
return blank;
|
||||
}
|
||||
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.language;
|
||||
}
|
||||
|
||||
const std::string& Epub::getSeries() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) {
|
||||
return blank;
|
||||
}
|
||||
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.series;
|
||||
}
|
||||
|
||||
const std::string& Epub::getSeriesIndex() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) {
|
||||
return blank;
|
||||
}
|
||||
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.seriesIndex;
|
||||
}
|
||||
|
||||
const std::string& Epub::getDescription() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) {
|
||||
return blank;
|
||||
}
|
||||
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.description;
|
||||
}
|
||||
|
||||
const std::string& Epub::getPublisher() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.publisher;
|
||||
}
|
||||
|
||||
const std::string& Epub::getDate() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.date;
|
||||
}
|
||||
|
||||
const std::string& Epub::getSubjects() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.subjects;
|
||||
}
|
||||
|
||||
const std::string& Epub::getRights() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.rights;
|
||||
}
|
||||
|
||||
const std::string& Epub::getContributor() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.contributor;
|
||||
}
|
||||
|
||||
const std::string& Epub::getIdentifier() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.identifier;
|
||||
}
|
||||
|
||||
const std::string& Epub::getRating() const {
|
||||
static std::string blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return blank;
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlank;
|
||||
return bookMetadataCache->coreMetadata.rating;
|
||||
}
|
||||
|
||||
const BookMetadataCache::BookMetadata& Epub::getMetadata() const {
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return kBlankMetadata;
|
||||
return bookMetadataCache->coreMetadata;
|
||||
}
|
||||
|
||||
std::string Epub::getCoverBmpPath(bool cropped) const {
|
||||
const auto coverFileName = std::string("cover") + (cropped ? "_crop" : "");
|
||||
return cachePath + "/" + coverFileName + ".bmp";
|
||||
|
||||
Reference in New Issue
Block a user