Skip to content

Commit

Permalink
AK: Simplify const T& versions of append/insert in SinglyLinkedList
Browse files Browse the repository at this point in the history
  • Loading branch information
deoxxa authored and awesomekling committed Dec 27, 2019
1 parent 115b315 commit fe3311d
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions AK/SinglyLinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,7 @@ class SinglyLinkedList {

void append(const T& value)
{
auto* node = new Node(value);
if (!m_head) {
m_head = node;
m_tail = node;
return;
}
m_tail->next = node;
m_tail = node;
append(T(value));
}

void append(T&& value)
Expand Down Expand Up @@ -196,12 +189,7 @@ class SinglyLinkedList {

void insert_before(Iterator iterator, const T& value)
{
auto* node = new Node(value);
node->next = iterator.m_node;
if (m_head == iterator.m_node)
m_head = node;
if (iterator.m_prev)
iterator.m_prev->next = node;
insert_before(T(value));
}

void insert_before(Iterator iterator, T&& value)
Expand All @@ -216,18 +204,7 @@ class SinglyLinkedList {

void insert_after(Iterator iterator, const T& value)
{
if (iterator.is_end()) {
append(value);
return;
}

auto* node = new Node(value);
node->next = iterator.m_node->next;

iterator.m_node->next = node;

if (m_tail == iterator.m_node)
m_tail = node;
insert_after(T(value));
}

void insert_after(Iterator iterator, T&& value)
Expand Down

0 comments on commit fe3311d

Please sign in to comment.