Skip to content

Commit

Permalink
Improve performance when using clear in Program
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Mar 12, 2024
1 parent 592713d commit 9ace184
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 6 additions & 2 deletions include/zasm/core/objectpool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ namespace zasm

void reset()
{
_blocks.clear();
_blocks.push_back(std::make_unique<Block>());
// Shrink to single block.
_blocks.resize(1);

// Reset slot to zero.
_blocks[0]->slot = 0;

_freeItem = nullptr;
}

Expand Down
13 changes: 11 additions & 2 deletions src/zasm/src/program/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,12 @@ namespace zasm

notifyObservers<true>(&Observer::onNodeDestroy, state.observer, node);

// Ensure node is not in the list anymore.
detach_<false>(node, state);
// If this is called from clear or from destructor we can skip unlinking.
if (!quickDestroy)
{
// Ensure node is not in the list anymore.
detach_<false>(node, state);
}

// Release.
auto* nodeToDestroy = detail::toInternal(node);
Expand Down Expand Up @@ -377,6 +381,11 @@ namespace zasm
node = next;
}

_state->head = nullptr;
_state->tail = nullptr;
_state->nextNodeId = {};
_state->nodeCount = 0;

_state->nodeMap.clear();
_state->sections.clear();
_state->labels.clear();
Expand Down

0 comments on commit 9ace184

Please sign in to comment.