From 31081e8ebfa843b5eb031df78524b5a62d60c15f Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Tue, 15 Jun 2021 11:28:15 -0700 Subject: [PATCH] AK: Remove now unused InlineLinkedList class All usages of AK::InlineLinkedList have been converted to AK::IntrusiveList. So it's time to retire our old friend. Note: The empty white space change in AK/CMakeLists.txt is to force CMake to re-glob the header files in the AK directory so incremental build will work when folks git pull this change locally. Otherwise they'll get errors, because CMake will attempt to install a file which no longer exists. --- AK/CMakeLists.txt | 1 + AK/Forward.h | 4 - AK/InlineLinkedList.h | 317 ------------------------------------------ 3 files changed, 1 insertion(+), 321 deletions(-) delete mode 100644 AK/InlineLinkedList.h diff --git a/AK/CMakeLists.txt b/AK/CMakeLists.txt index 509d3d4509..479e06f377 100644 --- a/AK/CMakeLists.txt +++ b/AK/CMakeLists.txt @@ -1,3 +1,4 @@ include(${CMAKE_SOURCE_DIR}/Meta/CMake/utils.cmake) + serenity_install_headers(AK) serenity_install_sources(AK) diff --git a/AK/Forward.h b/AK/Forward.h index 46c2ca12a8..45d2507958 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -63,9 +63,6 @@ class SinglyLinkedList; template class DoublyLinkedList; -template -class InlineLinkedList; - template class CircularQueue; @@ -139,7 +136,6 @@ using AK::FlyString; using AK::Function; using AK::HashMap; using AK::HashTable; -using AK::InlineLinkedList; using AK::InputBitStream; using AK::InputMemoryStream; using AK::InputStream; diff --git a/AK/InlineLinkedList.h b/AK/InlineLinkedList.h deleted file mode 100644 index 06a0f38dfe..0000000000 --- a/AK/InlineLinkedList.h +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include - -namespace AK { - -template -class InlineLinkedList; - -template -class InlineLinkedListIterator { -public: - bool operator!=(const InlineLinkedListIterator& other) const { return m_node != other.m_node; } - bool operator==(const InlineLinkedListIterator& other) const { return m_node == other.m_node; } - InlineLinkedListIterator& operator++() - { - m_node = m_node->next(); - return *this; - } - T& operator*() { return *m_node; } - T* operator->() { return m_node; } - bool is_end() const { return !m_node; } - static InlineLinkedListIterator universal_end() { return InlineLinkedListIterator(nullptr); } - -private: - friend InlineLinkedList; - explicit InlineLinkedListIterator(T* node) - : m_node(node) - { - } - T* m_node; -}; - -template -class InlineLinkedListNode { -public: - InlineLinkedListNode(); - - void set_prev(T*); - void set_next(T*); - - T* prev() const; - T* next() const; -}; - -template -inline InlineLinkedListNode::InlineLinkedListNode() -{ - set_prev(0); - set_next(0); -} - -template -inline void InlineLinkedListNode::set_prev(T* prev) -{ - static_cast(this)->m_prev = prev; -} - -template -inline void InlineLinkedListNode::set_next(T* next) -{ - static_cast(this)->m_next = next; -} - -template -inline T* InlineLinkedListNode::prev() const -{ - return static_cast(this)->m_prev; -} - -template -inline T* InlineLinkedListNode::next() const -{ - return static_cast(this)->m_next; -} - -template -class InlineLinkedList { -public: - InlineLinkedList() = default; - - bool is_empty() const { return !m_head; } - size_t size_slow() const; - void clear(); - - T* head() const { return m_head; } - T* remove_head(); - T* remove_tail(); - - T* tail() const { return m_tail; } - - void prepend(T*); - void append(T*); - void remove(T*); - void append(InlineLinkedList&); - void insert_before(T*, T*); - void insert_after(T*, T*); - - bool contains_slow(T* value) const - { - for (T* node = m_head; node; node = node->next()) { - if (node == value) - return true; - } - return false; - } - - template F> - IterationDecision for_each(F func) const - { - for (T* node = m_head; node; node = node->next()) { - IterationDecision decision = func(*node); - if (decision != IterationDecision::Continue) - return decision; - } - return IterationDecision::Continue; - } - - template F> - void for_each(F func) const - { - for (T* node = m_head; node; node = node->next()) - func(*node); - } - - using Iterator = InlineLinkedListIterator; - friend Iterator; - Iterator begin() { return Iterator(m_head); } - Iterator end() { return Iterator::universal_end(); } - - using ConstIterator = InlineLinkedListIterator; - friend ConstIterator; - ConstIterator begin() const { return ConstIterator(m_head); } - ConstIterator end() const { return ConstIterator::universal_end(); } - -private: - T* m_head { nullptr }; - T* m_tail { nullptr }; -}; - -template -inline size_t InlineLinkedList::size_slow() const -{ - size_t size = 0; - for (T* node = m_head; node; node = node->next()) - ++size; - return size; -} - -template -inline void InlineLinkedList::clear() -{ - m_head = 0; - m_tail = 0; -} - -template -inline void InlineLinkedList::prepend(T* node) -{ - if (!m_head) { - VERIFY(!m_tail); - m_head = node; - m_tail = node; - node->set_prev(0); - node->set_next(0); - return; - } - - VERIFY(m_tail); - m_head->set_prev(node); - node->set_next(m_head); - node->set_prev(0); - m_head = node; -} - -template -inline void InlineLinkedList::append(T* node) -{ - if (!m_tail) { - VERIFY(!m_head); - m_head = node; - m_tail = node; - node->set_prev(0); - node->set_next(0); - return; - } - - VERIFY(m_head); - m_tail->set_next(node); - node->set_prev(m_tail); - node->set_next(0); - m_tail = node; -} - -template -inline void InlineLinkedList::insert_before(T* before_node, T* node) -{ - VERIFY(before_node); - VERIFY(node); - VERIFY(before_node != node); - VERIFY(!is_empty()); - if (m_head == before_node) { - VERIFY(!before_node->prev()); - m_head = node; - node->set_prev(0); - node->set_next(before_node); - before_node->set_prev(node); - } else { - VERIFY(before_node->prev()); - node->set_prev(before_node->prev()); - before_node->prev()->set_next(node); - node->set_next(before_node); - before_node->set_prev(node); - } -} - -template -inline void InlineLinkedList::insert_after(T* after_node, T* node) -{ - VERIFY(after_node); - VERIFY(node); - VERIFY(after_node != node); - VERIFY(!is_empty()); - if (m_tail == after_node) { - VERIFY(!after_node->next()); - m_tail = node; - node->set_prev(after_node); - node->set_next(0); - after_node->set_next(node); - } else { - VERIFY(after_node->next()); - node->set_prev(after_node); - node->set_next(after_node->next()); - after_node->next()->set_prev(node); - after_node->set_next(node); - } -} - -template -inline void InlineLinkedList::remove(T* node) -{ - if (node->prev()) { - VERIFY(node != m_head); - node->prev()->set_next(node->next()); - } else { - VERIFY(node == m_head); - m_head = node->next(); - } - - if (node->next()) { - VERIFY(node != m_tail); - node->next()->set_prev(node->prev()); - } else { - VERIFY(node == m_tail); - m_tail = node->prev(); - } - - node->set_next(0); - node->set_prev(0); -} - -template -inline T* InlineLinkedList::remove_head() -{ - T* node = head(); - if (node) - remove(node); - return node; -} - -template -inline T* InlineLinkedList::remove_tail() -{ - T* node = tail(); - if (node) - remove(node); - return node; -} - -template -inline void InlineLinkedList::append(InlineLinkedList& other) -{ - if (!other.head()) - return; - - if (!head()) { - m_head = other.head(); - m_tail = other.tail(); - other.clear(); - return; - } - - VERIFY(tail()); - VERIFY(other.head()); - T* other_head = other.head(); - T* other_tail = other.tail(); - other.clear(); - - VERIFY(!m_tail->next()); - m_tail->set_next(other_head); - VERIFY(!other_head->prev()); - other_head->set_prev(m_tail); - m_tail = other_tail; -} - -} - -using AK::InlineLinkedList; -using AK::InlineLinkedListNode;