tag/Pool: use std::array

This commit is contained in:
Max Kellermann 2023-09-06 15:09:50 +02:00
parent 1448f52eac
commit 6c48f5ac63
1 changed files with 4 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#include "util/Cast.hxx"
#include "util/VarSize.hxx"
#include <array>
#include <cassert>
#include <cstdint>
#include <limits>
@ -15,8 +16,6 @@
Mutex tag_pool_lock;
static constexpr size_t NUM_SLOTS = 16127;
struct TagPoolSlot {
TagPoolSlot *next;
uint8_t ref = 1;
@ -46,7 +45,7 @@ TagPoolSlot::Create(TagPoolSlot *_next, TagType type,
value);
}
static TagPoolSlot *slots[NUM_SLOTS];
static std::array<TagPoolSlot *, 16127> slots;
static inline unsigned
calc_hash(TagType type, std::string_view p) noexcept
@ -81,13 +80,13 @@ tag_item_to_slot(TagItem *item) noexcept
static inline TagPoolSlot **
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 **
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 *