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/kstdio.h>.
This commit is contained in:
Andreas Kling 2020-02-10 11:55:34 +01:00
parent c8eaae3eaf
commit 6cbd72f54f
24 changed files with 3 additions and 63 deletions

View file

@ -27,7 +27,6 @@
#include "FileSystemPath.h"
#include "StringBuilder.h"
#include "Vector.h"
#include "kstdio.h"
namespace AK {

View file

@ -30,7 +30,6 @@
#include <AK/Optional.h>
#include <AK/StdLibExtras.h>
#include <AK/Vector.h>
#include <AK/kstdio.h>
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<V>::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<typename Traits<V>::PeekType> get(const K& key) const
{
auto it = find(key);

View file

@ -31,7 +31,6 @@
#include <AK/StdLibExtras.h>
#include <AK/TemporaryChange.h>
#include <AK/Traits.h>
#include <AK/kstdio.h>
namespace AK {
@ -163,8 +162,6 @@ public:
bool contains(const T&) const;
void clear();
void dump() const;
using Iterator = HashTableIterator<HashTable, T, typename Bucket::Iterator>;
friend Iterator;
Iterator begin() { return Iterator(*this, is_empty()); }
@ -380,21 +377,6 @@ auto HashTable<T, TraitsForT>::lookup(const T& value, int* bucket_index) const -
return m_buckets[hash % m_capacity];
}
template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::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;

View file

@ -115,7 +115,6 @@ static_assert(sizeof(IPv4Address) == 4);
template<>
struct Traits<IPv4Address> : public GenericTraits<IPv4Address> {
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)

View file

@ -178,7 +178,6 @@ template<typename T>
struct Traits<NonnullOwnPtr<T>> : public GenericTraits<NonnullOwnPtr<T>> {
using PeekType = const T*;
static unsigned hash(const NonnullOwnPtr<T>& p) { return int_hash((u32)p.ptr()); }
static void dump(const NonnullOwnPtr<T>& p) { kprintf("%p", p.ptr()); }
static bool equals(const NonnullOwnPtr<T>& a, const NonnullOwnPtr<T>& b) { return a.ptr() == b.ptr(); }
};

View file

@ -205,7 +205,6 @@ template<typename T>
struct Traits<OwnPtr<T>> : public GenericTraits<OwnPtr<T>> {
using PeekType = const T*;
static unsigned hash(const OwnPtr<T>& p) { return int_hash((u32)p.ptr()); }
static void dump(const OwnPtr<T>& p) { kprintf("%p", p.ptr()); }
static bool equals(const OwnPtr<T>& a, const OwnPtr<T>& b) { return a.ptr() == b.ptr(); }
};

View file

@ -32,7 +32,6 @@
#include <AK/StringView.h>
#include <AK/Traits.h>
#include <AK/Vector.h>
#include <AK/kstdio.h>
namespace AK {
@ -264,7 +263,6 @@ inline bool StringView::operator==(const String& string) const
template<>
struct Traits<String> : public GenericTraits<String> {
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<String> {

View file

@ -26,8 +26,7 @@
#pragma once
#include "HashFunctions.h"
#include "kstdio.h"
#include <AK/HashFunctions.h>
namespace AK {
@ -46,35 +45,30 @@ template<>
struct Traits<int> : public GenericTraits<int> {
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<unsigned> : public GenericTraits<unsigned> {
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<u16> : public GenericTraits<u16> {
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<u64> : public GenericTraits<u64> {
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<char> : public GenericTraits<char> {
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<typename T>
@ -84,7 +78,6 @@ struct Traits<T*> : public GenericTraits<T*> {
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; }
};

View file

@ -27,7 +27,6 @@
#pragma once
#include <AK/Traits.h>
#include <AK/kstdio.h>
class WindowIdentifier {
public:
@ -54,6 +53,5 @@ namespace AK {
template<>
struct Traits<WindowIdentifier> : public GenericTraits<WindowIdentifier> {
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()); }
};
}

View file

@ -24,7 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/kstdio.h>
#include <AK/String.h>
#include <assert.h>
#include <stdio.h>

View file

@ -26,7 +26,6 @@
#include "FullDevice.h"
#include <AK/StdLibExtras.h>
#include <AK/kstdio.h>
#include <LibC/errno_numbers.h>
FullDevice::FullDevice()

View file

@ -26,7 +26,6 @@
#include "NullDevice.h"
#include <AK/StdLibExtras.h>
#include <AK/kstdio.h>
static NullDevice* s_the;

View file

@ -26,7 +26,6 @@
#include "ZeroDevice.h"
#include <AK/StdLibExtras.h>
#include <AK/kstdio.h>
ZeroDevice::ZeroDevice()
: CharacterDevice(1, 5)

View file

@ -34,7 +34,6 @@
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <AK/WeakPtr.h>
#include <AK/kstdio.h>
#include <Kernel/Devices/BlockDevice.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/FileSystem/InodeMetadata.h>
@ -128,7 +127,6 @@ namespace AK {
template<>
struct Traits<InodeIdentifier> : public GenericTraits<InodeIdentifier> {
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()); }
};
}

View file

@ -79,11 +79,6 @@ struct Traits<IPv4SocketTuple> : public GenericTraits<IPv4SocketTuple> {
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());
}
};
}

View file

@ -82,7 +82,6 @@ namespace AK {
template<>
struct Traits<MACAddress> : public GenericTraits<MACAddress> {
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()); }
};
}

View file

@ -24,7 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/kstdio.h>
#include <Kernel/ProcessTracer.h>
ProcessTracer::ProcessTracer(pid_t pid)

View file

@ -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.

View file

@ -25,7 +25,6 @@
*/
#include <Kernel/Process.h>
#include <LibBareMetal/Output/kstdio.h>
extern "C" const char module_name[] = "TestModule";

View file

@ -27,7 +27,6 @@
#include "CMOS.h"
#include "Process.h"
#include <AK/Assertions.h>
#include <AK/kstdio.h>
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/Multiboot.h>

View file

@ -70,7 +70,6 @@
#include <Kernel/TTY/PTYMultiplexer.h>
#include <Kernel/TTY/VirtualConsole.h>
#include <Kernel/VM/MemoryManager.h>
#include <LibBareMetal/Output/kstdio.h>
[[noreturn]] static void init_stage2();
static void setup_serial_debug();

View file

@ -26,7 +26,6 @@
#include <AK/Assertions.h>
#include <AK/JsonObject.h>
#include <AK/kstdio.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Object.h>

View file

@ -25,7 +25,6 @@
*/
#include <AK/StringBuilder.h>
#include <AK/kstdio.h>
#include <LibELF/ELFImage.h>
ELFImage::ELFImage(const u8* buffer, size_t size)

View file

@ -27,7 +27,6 @@
#include "ELFLoader.h"
#include <AK/Demangle.h>
#include <AK/QuickSort.h>
#include <AK/kstdio.h>
#ifdef KERNEL
#include <Kernel/VM/MemoryManager.h>