Skip to content

Commit

Permalink
Merge pull request #113 from zyantific/clear-improvement
Browse files Browse the repository at this point in the history
Program::clear optimization
  • Loading branch information
ZehMatt authored Mar 12, 2024
2 parents f615882 + 65dda86 commit 44851ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 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
7 changes: 3 additions & 4 deletions src/benchmark/benchmarks/benchmark.instructioninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace zasm::benchmarks

Program program(MachineMode::AMD64);
Assembler assembler(program);
Serializer serializer;

for (auto s : state)
{
Expand All @@ -23,17 +22,17 @@ namespace zasm::benchmarks

program.clear();
assembler.setCursor(nullptr);

const auto& instrData = tests::data::Instructions[i];
instrData.emitter(assembler);

const auto& instr = assembler.getCursor()->get<Instruction>();
state.ResumeTiming();

const auto instrInfo = instr.getDetail(program.getMode());
benchmark::DoNotOptimize(instrInfo);

}

state.counters["InstructionInfos"] = benchmark::Counter(
static_cast<double>(count), benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000);
}
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 44851ce

Please sign in to comment.