From 4ce23eb2f6fcebb8f977c0f686cf60f4a5eaa62b Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 3 Nov 2023 10:38:52 +0100 Subject: [PATCH] Introduce helper method `DirentPool::getDirentSlot` --- src/writer/direntPool.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/writer/direntPool.h b/src/writer/direntPool.h index ee90f61a7..e8caced8c 100644 --- a/src/writer/direntPool.h +++ b/src/writer/direntPool.h @@ -44,6 +44,14 @@ namespace zim delete [] (reinterpret_cast(pool)); } + /* Return a *NOT constructed* pointer to a dirent */ + Dirent* getDirentSlot() { + if (direntIndex == 0xFFFF) { + allocate_new_pool(); + } + auto dirent = pools.back() + direntIndex++; + return dirent; + } public: DirentPool() : @@ -65,28 +73,19 @@ namespace zim } Dirent* getClassicDirent(NS ns, const std::string& path, const std::string& title, uint16_t mimetype) { - if (direntIndex == 0xFFFF) { - allocate_new_pool(); - } - auto dirent = pools.back() + direntIndex++; + auto dirent = getDirentSlot(); new (dirent) Dirent(ns, path, title, mimetype); return dirent; } Dirent* getRedirectDirent(NS ns, const std::string& path, const std::string& title, NS targetNs, const std::string& targetPath) { - if (direntIndex == 0xFFFF) { - allocate_new_pool(); - } - auto dirent = pools.back() + direntIndex++; + auto dirent = getDirentSlot(); new (dirent) Dirent(ns, path, title, targetNs, targetPath); return dirent; } Dirent* getCloneDirent(const std::string& path, const std::string& title, const Dirent& target) { - if (direntIndex == 0xFFFF) { - allocate_new_pool(); - } - auto dirent = pools.back() + direntIndex++; + auto dirent = getDirentSlot(); new (dirent) Dirent(path, title, target); return dirent; }