Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 6fad4f1a authored by Quentin Khan's avatar Quentin Khan
Browse files

FNode: reduce FNode::split allocation call count

An allocation was made for each child. Now an array of children is
allocated in one go.
parent a7e1ac83
No related branches found
No related tags found
No related merge requests found
...@@ -251,9 +251,7 @@ public: ...@@ -251,9 +251,7 @@ public:
/** Destructor */ /** Destructor */
~FNode() { ~FNode() {
for(auto&& child : _children) { this->delete_children();
delete child;
}
} }
...@@ -634,12 +632,14 @@ private: ...@@ -634,12 +632,14 @@ private:
/** Allocates this node's children */ /** Allocates this node's children */
void create_children() { void create_children() {
using uninit_FNode = typename std::aligned_storage<sizeof(FNode)>::type;
std::size_t idx = 0; std::size_t idx = 0;
// Remove this node from tree leaf list // Remove this node from tree leaf list
getTree().leaves().erase(this); getTree().leaves().erase(this);
// Create the children, add them to tree leaf list // Create the children, add them to tree leaf list
FNode* tmp = reinterpret_cast<FNode*>(new uninit_FNode[child_count]);
for(FNode*& child : getChildren()) { for(FNode*& child : getChildren()) {
child = new FNode(*this, idx); child = new(tmp+idx) FNode(*this, idx);
getTree().leaves().insert(child); getTree().leaves().insert(child);
++idx; ++idx;
} }
...@@ -651,12 +651,16 @@ private: ...@@ -651,12 +651,16 @@ private:
/* Deletes this node's children */ /* Deletes this node's children */
void delete_children() { void delete_children() {
using uninit_FNode = typename std::aligned_storage<sizeof(FNode)>::type;
// Remove children from tree leaf list, free them // Remove children from tree leaf list, free them
for(FNode*& child : getChildren()) { for(FNode*& child : getChildren()) {
getTree().leaves().erase(child); if(child) {
delete child; getTree().leaves().erase(child);
child = nullptr; child->~FNode();
}
} }
delete[] reinterpret_cast<uninit_FNode*>(getChild(0));
std::fill_n(this->getChildren().data(), child_count, nullptr);
// Insert this node in tree leaf list // Insert this node in tree leaf list
getTree().leaves().insert(this); getTree().leaves().insert(this);
// Set leaf status for this node // Set leaf status for this node
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment