tag/Pool: use std::array
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "util/Cast.hxx"
|
#include "util/Cast.hxx"
|
||||||
#include "util/VarSize.hxx"
|
#include "util/VarSize.hxx"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -15,8 +16,6 @@
|
|||||||
|
|
||||||
Mutex tag_pool_lock;
|
Mutex tag_pool_lock;
|
||||||
|
|
||||||
static constexpr size_t NUM_SLOTS = 16127;
|
|
||||||
|
|
||||||
struct TagPoolSlot {
|
struct TagPoolSlot {
|
||||||
TagPoolSlot *next;
|
TagPoolSlot *next;
|
||||||
uint8_t ref = 1;
|
uint8_t ref = 1;
|
||||||
@@ -46,7 +45,7 @@ TagPoolSlot::Create(TagPoolSlot *_next, TagType type,
|
|||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TagPoolSlot *slots[NUM_SLOTS];
|
static std::array<TagPoolSlot *, 16127> slots;
|
||||||
|
|
||||||
static inline unsigned
|
static inline unsigned
|
||||||
calc_hash(TagType type, std::string_view p) noexcept
|
calc_hash(TagType type, std::string_view p) noexcept
|
||||||
@@ -81,13 +80,13 @@ tag_item_to_slot(TagItem *item) noexcept
|
|||||||
static inline TagPoolSlot **
|
static inline TagPoolSlot **
|
||||||
tag_value_slot_p(TagType type, std::string_view value) noexcept
|
tag_value_slot_p(TagType type, std::string_view value) noexcept
|
||||||
{
|
{
|
||||||
return &slots[calc_hash(type, value) % NUM_SLOTS];
|
return &slots[calc_hash(type, value) % slots.size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline TagPoolSlot **
|
static inline TagPoolSlot **
|
||||||
tag_value_slot_p(TagType type, const char *value) noexcept
|
tag_value_slot_p(TagType type, const char *value) noexcept
|
||||||
{
|
{
|
||||||
return &slots[calc_hash(type, value) % NUM_SLOTS];
|
return &slots[calc_hash(type, value) % slots.size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
TagItem *
|
TagItem *
|
||||||
|
Reference in New Issue
Block a user