Skip to content

Commit

Permalink
Introduce helper method DirentPool::getDirentSlot
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Nov 3, 2023
1 parent 76cdca2 commit ed85541
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/writer/direntPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ namespace zim
delete [] (reinterpret_cast<char*>(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() :
Expand All @@ -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;
}
Expand Down

0 comments on commit ed85541

Please sign in to comment.