Add support for per type default memory domain
This commit is contained in:
parent
c79cd59314
commit
32319aca45
|
@ -30,6 +30,7 @@ enum class MemoryDomain
|
|||
Registers,
|
||||
Client,
|
||||
WordDB,
|
||||
Selections,
|
||||
Count
|
||||
};
|
||||
|
||||
|
@ -54,6 +55,7 @@ inline const char* domain_name(MemoryDomain domain)
|
|||
case MemoryDomain::Values: return "Values";
|
||||
case MemoryDomain::Registers: return "Registers";
|
||||
case MemoryDomain::Client: return "Client";
|
||||
case MemoryDomain::Selections: return "Selections";
|
||||
case MemoryDomain::Count: break;
|
||||
}
|
||||
kak_assert(false);
|
||||
|
@ -118,6 +120,15 @@ bool operator!=(const Allocator<T1, d1>& lhs, const Allocator<T2, d2>& rhs)
|
|||
return d1 != d2;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct TypeDomain
|
||||
{
|
||||
static constexpr MemoryDomain domain = TypeDomain::helper((T*)nullptr);
|
||||
private:
|
||||
template<typename U> static decltype(U::Domain) constexpr helper(U*) { return U::Domain; }
|
||||
static constexpr MemoryDomain helper(...) { return MemoryDomain::Undefined; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // memory_hh_INCLUDED
|
||||
|
|
|
@ -11,6 +11,8 @@ using CaptureList = Vector<String>;
|
|||
// A selection is a Selection, associated with a CaptureList
|
||||
struct Selection
|
||||
{
|
||||
static constexpr MemoryDomain Domain = MemoryDomain::Selections;
|
||||
|
||||
Selection() = default;
|
||||
Selection(ByteCoord pos) : Selection(pos,pos) {}
|
||||
Selection(ByteCoord anchor, ByteCoord cursor,
|
||||
|
@ -68,6 +70,8 @@ enum class InsertMode : unsigned
|
|||
|
||||
struct SelectionList
|
||||
{
|
||||
static constexpr MemoryDomain Domain = MemoryDomain::Selections;
|
||||
|
||||
SelectionList(Buffer& buffer, Selection s);
|
||||
SelectionList(Buffer& buffer, Selection s, size_t timestamp);
|
||||
SelectionList(Buffer& buffer, Vector<Selection> s);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
template<typename Key, typename Value, MemoryDomain domain = MemoryDomain::Undefined>
|
||||
template<typename Key, typename Value, MemoryDomain domain = TypeDomain<Key>::domain>
|
||||
using UnorderedMap = std::unordered_map<Key, Value, Hash<Key>, std::equal_to<Key>,
|
||||
Allocator<std::pair<const Key, Value>, domain>>;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
template<typename T, MemoryDomain domain = MemoryDomain::Undefined>
|
||||
template<typename T, MemoryDomain domain = TypeDomain<T>::domain>
|
||||
using Vector = std::vector<T, Allocator<T, domain>>;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user