Skip to content

Commit

Permalink
AK: Remove bitrotted Traits::dump() mechanism
Browse files Browse the repository at this point in the history
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>.
  • Loading branch information
awesomekling committed Feb 10, 2020
1 parent c8eaae3 commit 6cbd72f
Show file tree
Hide file tree
Showing 24 changed files with 3 additions and 63 deletions.
1 change: 0 additions & 1 deletion AK/FileSystemPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "FileSystemPath.h"
#include "StringBuilder.h"
#include "Vector.h"
#include "kstdio.h"

namespace AK {

Expand Down
10 changes: 0 additions & 10 deletions AK/HashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <AK/Optional.h>
#include <AK/StdLibExtras.h>
#include <AK/Vector.h>
#include <AK/kstdio.h>

namespace AK {

Expand All @@ -45,13 +44,6 @@ class HashMap {
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:
Expand Down Expand Up @@ -102,8 +94,6 @@ class HashMap {

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);
Expand Down
18 changes: 0 additions & 18 deletions AK/HashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <AK/StdLibExtras.h>
#include <AK/TemporaryChange.h>
#include <AK/Traits.h>
#include <AK/kstdio.h>

namespace AK {

Expand Down Expand Up @@ -163,8 +162,6 @@ class HashTable {
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()); }
Expand Down Expand Up @@ -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;
1 change: 0 additions & 1 deletion AK/IPv4Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion AK/NonnullOwnPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
};

Expand Down
1 change: 0 additions & 1 deletion AK/OwnPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
};

Expand Down
2 changes: 0 additions & 2 deletions AK/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <AK/StringView.h>
#include <AK/Traits.h>
#include <AK/Vector.h>
#include <AK/kstdio.h>

namespace AK {

Expand Down Expand Up @@ -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> {
Expand Down
9 changes: 1 addition & 8 deletions AK/Traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

#pragma once

#include "HashFunctions.h"
#include "kstdio.h"
#include <AK/HashFunctions.h>

namespace AK {

Expand All @@ -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>
Expand All @@ -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; }
};

Expand Down
2 changes: 0 additions & 2 deletions Applications/Taskbar/WindowIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#pragma once

#include <AK/Traits.h>
#include <AK/kstdio.h>

class WindowIdentifier {
public:
Expand All @@ -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()); }
};
}
1 change: 0 additions & 1 deletion Demos/DynamicLink/LinkLib/DynamicLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion Kernel/Devices/FullDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "FullDevice.h"
#include <AK/StdLibExtras.h>
#include <AK/kstdio.h>
#include <LibC/errno_numbers.h>

FullDevice::FullDevice()
Expand Down
1 change: 0 additions & 1 deletion Kernel/Devices/NullDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "NullDevice.h"
#include <AK/StdLibExtras.h>
#include <AK/kstdio.h>

static NullDevice* s_the;

Expand Down
1 change: 0 additions & 1 deletion Kernel/Devices/ZeroDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "ZeroDevice.h"
#include <AK/StdLibExtras.h>
#include <AK/kstdio.h>

ZeroDevice::ZeroDevice()
: CharacterDevice(1, 5)
Expand Down
2 changes: 0 additions & 2 deletions Kernel/FileSystem/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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()); }
};

}
5 changes: 0 additions & 5 deletions Kernel/Net/IPv4SocketTuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
};

}
1 change: 0 additions & 1 deletion Kernel/Net/MACAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()); }
};

}
1 change: 0 additions & 1 deletion Kernel/ProcessTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Kernel/SharedBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion Kernel/TestModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/

#include <Kernel/Process.h>
#include <LibBareMetal/Output/kstdio.h>

extern "C" const char module_name[] = "TestModule";

Expand Down
1 change: 0 additions & 1 deletion Kernel/VM/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion Kernel/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion Libraries/LibCore/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion Libraries/LibELF/ELFImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/

#include <AK/StringBuilder.h>
#include <AK/kstdio.h>
#include <LibELF/ELFImage.h>

ELFImage::ELFImage(const u8* buffer, size_t size)
Expand Down
1 change: 0 additions & 1 deletion Libraries/LibELF/ELFLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 6cbd72f

Please sign in to comment.