Skip to content

Commit

Permalink
Further abstract some calls in SLL
Browse files Browse the repository at this point in the history
This is a part of a rework that should make it
safer to use and properly managed.
  • Loading branch information
YuriSizov committed Sep 28, 2024
1 parent 5966a68 commit 0ed00ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/sequencer/base/mml_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ MMLEvent *MMLExecutor::on_repeat_all(MMLEvent *p_event) {
}

MMLEvent *MMLExecutor::on_repeat_begin(MMLEvent *p_event) {
SinglyLinkedList<int> *counter = SinglyLinkedList<int>::alloc(p_event->get_data());
counter->link(_repeat_counters);
_repeat_counters = counter;
_repeat_counters = _repeat_counters->prepend(p_event->get_data());

return p_event->get_next();
}
Expand Down
19 changes: 8 additions & 11 deletions src/sequencer/simml_envelope_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@ void SiMMLEnvelopeTable::copy_from(const Ref<SiMMLEnvelopeTable> &p_source) {
return;
}

SinglyLinkedList<int> *curr_source = p_source->head;
SinglyLinkedList<int> *curr_destination = nullptr;
for (; curr_source != p_source->tail; curr_source = curr_source->next()) {
SinglyLinkedList<int> *sll_value = SinglyLinkedList<int>::alloc(curr_source->value);
if (curr_destination) {
curr_destination->link(sll_value);
curr_destination = sll_value;
} else {
head = sll_value;
curr_destination = head;
}
head = p_source->head->clone_element();

SinglyLinkedList<int> *target = head;
SinglyLinkedList<int> *current = p_source->head->next();

while (current != p_source->tail) {
target = target->append(current->value);
current = current->next();
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/templates/singly_linked_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SinglyLinkedList {
// NOTE: Original code called it `i`. There is no special accessor, so we opt for a better public name.
T value = 0;

static SinglyLinkedList<T> *alloc(int p_value = 0) {
static SinglyLinkedList<T> *alloc(T p_value) {
SinglyLinkedList<T> *ret;

if (_free_list) {
Expand Down Expand Up @@ -139,6 +139,12 @@ class SinglyLinkedList {
return _next;
}

SinglyLinkedList<T> *prepend(T p_value) {
SinglyLinkedList<T> *head = alloc(p_value);
head->_next = this;
return head;
}

void link(SinglyLinkedList<T> *p_element) {
_next = p_element;
}
Expand All @@ -147,6 +153,12 @@ class SinglyLinkedList {
_next = nullptr;
}

//

SinglyLinkedList<T> *clone_element() {
return alloc(value);
}

SinglyLinkedList(T p_value) {
value = p_value;
}
Expand Down

0 comments on commit 0ed00ce

Please sign in to comment.