From 6cbd72f54f806a4bb78fc751523f022e887894ea Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 10 Feb 2020 11:55:34 +0100 Subject: [PATCH] AK: Remove bitrotted Traits::dump() mechanism This was only used by HashTable::dump() which I used when doing the first HashTable implementation. Removing this allows us to also remove most includes of . --- AK/FileSystemPath.cpp | 1 - AK/HashMap.h | 10 ---------- AK/HashTable.h | 18 ------------------ AK/IPv4Address.h | 1 - AK/NonnullOwnPtr.h | 1 - AK/OwnPtr.h | 1 - AK/String.h | 2 -- AK/Traits.h | 9 +-------- Applications/Taskbar/WindowIdentifier.h | 2 -- Demos/DynamicLink/LinkLib/DynamicLib.cpp | 1 - Kernel/Devices/FullDevice.cpp | 1 - Kernel/Devices/NullDevice.cpp | 1 - Kernel/Devices/ZeroDevice.cpp | 1 - Kernel/FileSystem/FileSystem.h | 2 -- Kernel/Net/IPv4SocketTuple.h | 5 ----- Kernel/Net/MACAddress.h | 1 - Kernel/ProcessTracer.cpp | 1 - Kernel/SharedBuffer.cpp | 2 ++ Kernel/TestModule.cpp | 1 - Kernel/VM/MemoryManager.cpp | 1 - Kernel/init.cpp | 1 - Libraries/LibCore/Object.cpp | 1 - Libraries/LibELF/ELFImage.cpp | 1 - Libraries/LibELF/ELFLoader.cpp | 1 - 24 files changed, 3 insertions(+), 63 deletions(-) diff --git a/AK/FileSystemPath.cpp b/AK/FileSystemPath.cpp index 1bb4f5b9618..f2804187130 100644 --- a/AK/FileSystemPath.cpp +++ b/AK/FileSystemPath.cpp @@ -27,7 +27,6 @@ #include "FileSystemPath.h" #include "StringBuilder.h" #include "Vector.h" -#include "kstdio.h" namespace AK { diff --git a/AK/HashMap.h b/AK/HashMap.h index 4818d6d0add..6c5487026a1 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -30,7 +30,6 @@ #include #include #include -#include namespace AK { @@ -45,13 +44,6 @@ private: struct EntryTraits { static unsigned hash(const Entry& entry) { return KeyTraits::hash(entry.key); } static bool equals(const Entry& a, const Entry& b) { return KeyTraits::equals(a.key, b.key); } - static void dump(const Entry& entry) - { - kprintf("key="); - KeyTraits::dump(entry.key); - kprintf(" value="); - Traits::dump(entry.value); - } }; public: @@ -102,8 +94,6 @@ public: void ensure_capacity(int capacity) { m_table.ensure_capacity(capacity); } - void dump() const { m_table.dump(); } - Optional::PeekType> get(const K& key) const { auto it = find(key); diff --git a/AK/HashTable.h b/AK/HashTable.h index 6cdbe8598f8..43956b6232a 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -31,7 +31,6 @@ #include #include #include -#include namespace AK { @@ -163,8 +162,6 @@ public: bool contains(const T&) const; void clear(); - void dump() const; - using Iterator = HashTableIterator; friend Iterator; Iterator begin() { return Iterator(*this, is_empty()); } @@ -380,21 +377,6 @@ auto HashTable::lookup(const T& value, int* bucket_index) const - return m_buckets[hash % m_capacity]; } -template -void HashTable::dump() const -{ - kprintf("HashTable{%p} m_size=%u, m_capacity=%u, m_buckets=%p\n", this, m_size, m_capacity, m_buckets); - for (int i = 0; i < m_capacity; ++i) { - auto& bucket = m_buckets[i]; - kprintf("Bucket %u\n", i); - for (auto& e : bucket) { - kprintf(" > "); - TraitsForT::dump(e); - kprintf("\n"); - } - } -} - } using AK::HashTable; diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index 71d954cc9bc..be729938e23 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -115,7 +115,6 @@ static_assert(sizeof(IPv4Address) == 4); template<> struct Traits : public GenericTraits { static unsigned hash(const IPv4Address& address) { return string_hash((const char*)&address, sizeof(address)); } - static void dump(const IPv4Address& address) { kprintf("%s", address.to_string().characters()); } }; inline const LogStream& operator<<(const LogStream& stream, const IPv4Address& value) diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index 5af4d083479..c3a78a6ff58 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -178,7 +178,6 @@ template struct Traits> : public GenericTraits> { using PeekType = const T*; static unsigned hash(const NonnullOwnPtr& p) { return int_hash((u32)p.ptr()); } - static void dump(const NonnullOwnPtr& p) { kprintf("%p", p.ptr()); } static bool equals(const NonnullOwnPtr& a, const NonnullOwnPtr& b) { return a.ptr() == b.ptr(); } }; diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index 162c756e17f..66809382011 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -205,7 +205,6 @@ template struct Traits> : public GenericTraits> { using PeekType = const T*; static unsigned hash(const OwnPtr& p) { return int_hash((u32)p.ptr()); } - static void dump(const OwnPtr& p) { kprintf("%p", p.ptr()); } static bool equals(const OwnPtr& a, const OwnPtr& b) { return a.ptr() == b.ptr(); } }; diff --git a/AK/String.h b/AK/String.h index 74ac6a885d9..e2c4c720367 100644 --- a/AK/String.h +++ b/AK/String.h @@ -32,7 +32,6 @@ #include #include #include -#include namespace AK { @@ -264,7 +263,6 @@ inline bool StringView::operator==(const String& string) const template<> struct Traits : public GenericTraits { static unsigned hash(const String& s) { return s.impl() ? s.impl()->hash() : 0; } - static void dump(const String& s) { kprintf("%s", s.characters()); } }; struct CaseInsensitiveStringTraits : public AK::Traits { diff --git a/AK/Traits.h b/AK/Traits.h index a4e9a2dbcf6..ff6921150df 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -26,8 +26,7 @@ #pragma once -#include "HashFunctions.h" -#include "kstdio.h" +#include namespace AK { @@ -46,35 +45,30 @@ template<> struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } static unsigned hash(int i) { return int_hash(i); } - static void dump(int i) { kprintf("%d", i); } }; template<> struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } static unsigned hash(unsigned u) { return int_hash(u); } - static void dump(unsigned u) { kprintf("%u", u); } }; template<> struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } static unsigned hash(u16 u) { return int_hash(u); } - static void dump(u16 u) { kprintf("%u", u); } }; template<> struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } static unsigned hash(u64 u) { return u64_hash(u); } - static void dump(u64 u) { kprintf("%u", (unsigned)u); } // FIXME: Implement unsigned long long printf specifier, instead of this sadness :( }; template<> struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } static unsigned hash(char c) { return int_hash(c); } - static void dump(char c) { kprintf("%c", c); } }; template @@ -84,7 +78,6 @@ struct Traits : public GenericTraits { return int_hash((unsigned)(__PTRDIFF_TYPE__)p); } static constexpr bool is_trivial() { return true; } - static void dump(const T* p) { kprintf("%p", p); } static bool equals(const T* a, const T* b) { return a == b; } }; diff --git a/Applications/Taskbar/WindowIdentifier.h b/Applications/Taskbar/WindowIdentifier.h index 1bd8e34743c..cdb645449ae 100644 --- a/Applications/Taskbar/WindowIdentifier.h +++ b/Applications/Taskbar/WindowIdentifier.h @@ -27,7 +27,6 @@ #pragma once #include -#include class WindowIdentifier { public: @@ -54,6 +53,5 @@ namespace AK { template<> struct Traits : public GenericTraits { static unsigned hash(const WindowIdentifier& w) { return pair_int_hash(w.client_id(), w.window_id()); } - static void dump(const WindowIdentifier& w) { kprintf("WindowIdentifier(%d, %d)", w.client_id(), w.window_id()); } }; } diff --git a/Demos/DynamicLink/LinkLib/DynamicLib.cpp b/Demos/DynamicLink/LinkLib/DynamicLib.cpp index cc92f3ee1a0..0b92684c36c 100644 --- a/Demos/DynamicLink/LinkLib/DynamicLib.cpp +++ b/Demos/DynamicLink/LinkLib/DynamicLib.cpp @@ -24,7 +24,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include #include diff --git a/Kernel/Devices/FullDevice.cpp b/Kernel/Devices/FullDevice.cpp index d7251e63f30..7cd1be851b2 100644 --- a/Kernel/Devices/FullDevice.cpp +++ b/Kernel/Devices/FullDevice.cpp @@ -26,7 +26,6 @@ #include "FullDevice.h" #include -#include #include FullDevice::FullDevice() diff --git a/Kernel/Devices/NullDevice.cpp b/Kernel/Devices/NullDevice.cpp index 6b90c9a2e7c..910a4385268 100644 --- a/Kernel/Devices/NullDevice.cpp +++ b/Kernel/Devices/NullDevice.cpp @@ -26,7 +26,6 @@ #include "NullDevice.h" #include -#include static NullDevice* s_the; diff --git a/Kernel/Devices/ZeroDevice.cpp b/Kernel/Devices/ZeroDevice.cpp index 25915d68cb3..c58dc6936e2 100644 --- a/Kernel/Devices/ZeroDevice.cpp +++ b/Kernel/Devices/ZeroDevice.cpp @@ -26,7 +26,6 @@ #include "ZeroDevice.h" #include -#include ZeroDevice::ZeroDevice() : CharacterDevice(1, 5) diff --git a/Kernel/FileSystem/FileSystem.h b/Kernel/FileSystem/FileSystem.h index 76ba9ea737f..e11c58ef931 100644 --- a/Kernel/FileSystem/FileSystem.h +++ b/Kernel/FileSystem/FileSystem.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -128,7 +127,6 @@ namespace AK { template<> struct Traits : public GenericTraits { static unsigned hash(const InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index()); } - static void dump(const InodeIdentifier& inode) { kprintf("%02u:%08u", inode.fsid(), inode.index()); } }; } diff --git a/Kernel/Net/IPv4SocketTuple.h b/Kernel/Net/IPv4SocketTuple.h index 5e21932aea2..56876e28184 100644 --- a/Kernel/Net/IPv4SocketTuple.h +++ b/Kernel/Net/IPv4SocketTuple.h @@ -79,11 +79,6 @@ struct Traits : public GenericTraits { auto h2 = pair_int_hash(tuple.peer_address().to_u32(), tuple.peer_port()); return pair_int_hash(h1, h2); } - - static void dump(const IPv4SocketTuple& tuple) - { - kprintf("%s", tuple.to_string().characters()); - } }; } diff --git a/Kernel/Net/MACAddress.h b/Kernel/Net/MACAddress.h index e6456a6677e..4ad391d0fa4 100644 --- a/Kernel/Net/MACAddress.h +++ b/Kernel/Net/MACAddress.h @@ -82,7 +82,6 @@ namespace AK { template<> struct Traits : public GenericTraits { static unsigned hash(const MACAddress& address) { return string_hash((const char*)&address, sizeof(address)); } - static void dump(const MACAddress& address) { kprintf("%s", address.to_string().characters()); } }; } diff --git a/Kernel/ProcessTracer.cpp b/Kernel/ProcessTracer.cpp index ee19bcc5814..1d491d6fd77 100644 --- a/Kernel/ProcessTracer.cpp +++ b/Kernel/ProcessTracer.cpp @@ -24,7 +24,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include ProcessTracer::ProcessTracer(pid_t pid) diff --git a/Kernel/SharedBuffer.cpp b/Kernel/SharedBuffer.cpp index 9d5454ac4fe..7371ec79e04 100644 --- a/Kernel/SharedBuffer.cpp +++ b/Kernel/SharedBuffer.cpp @@ -100,6 +100,8 @@ void* SharedBuffer::ref_for_process_and_get_address(Process& process) void SharedBuffer::share_with(pid_t peer_pid) { LOCKER(shared_buffers().lock()); + if (m_global) + return; for (auto& ref : m_refs) { if (ref.pid == peer_pid) { // don't increment the reference count yet; let them get_shared_buffer it first. diff --git a/Kernel/TestModule.cpp b/Kernel/TestModule.cpp index b15ae5ce3ac..83ae66927b7 100644 --- a/Kernel/TestModule.cpp +++ b/Kernel/TestModule.cpp @@ -25,7 +25,6 @@ */ #include -#include extern "C" const char module_name[] = "TestModule"; diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 9fb49e59fca..b1abf84255d 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -27,7 +27,6 @@ #include "CMOS.h" #include "Process.h" #include -#include #include #include #include diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 76c62683400..a592e1107e7 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -70,7 +70,6 @@ #include #include #include -#include [[noreturn]] static void init_stage2(); static void setup_serial_debug(); diff --git a/Libraries/LibCore/Object.cpp b/Libraries/LibCore/Object.cpp index ad73176f4e6..87b1f7c5d3e 100644 --- a/Libraries/LibCore/Object.cpp +++ b/Libraries/LibCore/Object.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/Libraries/LibELF/ELFImage.cpp b/Libraries/LibELF/ELFImage.cpp index 73ba4c37b57..9f967d1fcc8 100644 --- a/Libraries/LibELF/ELFImage.cpp +++ b/Libraries/LibELF/ELFImage.cpp @@ -25,7 +25,6 @@ */ #include -#include #include ELFImage::ELFImage(const u8* buffer, size_t size) diff --git a/Libraries/LibELF/ELFLoader.cpp b/Libraries/LibELF/ELFLoader.cpp index 398ded23cc5..610861ae176 100644 --- a/Libraries/LibELF/ELFLoader.cpp +++ b/Libraries/LibELF/ELFLoader.cpp @@ -27,7 +27,6 @@ #include "ELFLoader.h" #include #include -#include #ifdef KERNEL #include