mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
b48b6c0caa
This can definitely be improved with better trivial type detection and by using the TypedTransfer template in more places. It's a bit annoying that we can't get <type_traits> in Vector.h since it's included in the toolchain compilation before we have libstdc++.
57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "HashFunctions.h"
|
|
#include "kstdio.h"
|
|
|
|
namespace AK {
|
|
|
|
template<typename T>
|
|
struct GenericTraits {
|
|
static bool equals(const T& a, const T& b) { return a == b; }
|
|
};
|
|
|
|
template<typename T>
|
|
struct Traits : public GenericTraits<T> {
|
|
static constexpr bool is_trivial() { return false; }
|
|
};
|
|
|
|
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<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>
|
|
struct Traits<T*> {
|
|
static unsigned hash(const T* p)
|
|
{
|
|
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; }
|
|
};
|
|
|
|
}
|