tag/TagPool: rename struct slot to TagPoolSlot

This commit is contained in:
Max Kellermann 2014-01-07 23:12:24 +01:00
parent 70eb9335bd
commit 8a30c7992d

View File

@ -31,13 +31,13 @@ Mutex tag_pool_lock;
#define NUM_SLOTS 4096 #define NUM_SLOTS 4096
struct slot { struct TagPoolSlot {
struct slot *next; TagPoolSlot *next;
unsigned char ref; unsigned char ref;
TagItem item; TagItem item;
} gcc_packed; } gcc_packed;
static struct slot *slots[NUM_SLOTS]; static TagPoolSlot *slots[NUM_SLOTS];
static inline unsigned static inline unsigned
calc_hash_n(TagType type, const char *p, size_t length) calc_hash_n(TagType type, const char *p, size_t length)
@ -65,19 +65,18 @@ calc_hash(TagType type, const char *p)
return hash ^ type; return hash ^ type;
} }
static inline struct slot * static inline constexpr TagPoolSlot *
tag_item_to_slot(TagItem *item) tag_item_to_slot(TagItem *item)
{ {
return ContainerCast(item, slot, item); return ContainerCast(item, TagPoolSlot, item);
} }
static struct slot *slot_alloc(struct slot *next, static TagPoolSlot *
TagType type, slot_alloc(TagPoolSlot *next, TagType type, const char *value, int length)
const char *value, int length)
{ {
struct slot *slot; TagPoolSlot *slot;
slot = (struct slot *) slot = (TagPoolSlot *)
g_malloc(sizeof(*slot) - sizeof(slot->item.value) + length + 1); g_malloc(sizeof(*slot) - sizeof(slot->item.value) + length + 1);
slot->next = next; slot->next = next;
slot->ref = 1; slot->ref = 1;
@ -90,7 +89,7 @@ static struct slot *slot_alloc(struct slot *next,
TagItem * TagItem *
tag_pool_get_item(TagType type, const char *value, size_t length) tag_pool_get_item(TagType type, const char *value, size_t length)
{ {
struct slot **slot_p, *slot; TagPoolSlot **slot_p, *slot;
slot_p = &slots[calc_hash_n(type, value, length) % NUM_SLOTS]; slot_p = &slots[calc_hash_n(type, value, length) % NUM_SLOTS];
for (slot = *slot_p; slot != nullptr; slot = slot->next) { for (slot = *slot_p; slot != nullptr; slot = slot->next) {
@ -112,7 +111,7 @@ tag_pool_get_item(TagType type, const char *value, size_t length)
TagItem * TagItem *
tag_pool_dup_item(TagItem *item) tag_pool_dup_item(TagItem *item)
{ {
struct slot *slot = tag_item_to_slot(item); TagPoolSlot *slot = tag_item_to_slot(item);
assert(slot->ref > 0); assert(slot->ref > 0);
@ -123,7 +122,7 @@ tag_pool_dup_item(TagItem *item)
/* the reference counter overflows above 0xff; /* the reference counter overflows above 0xff;
duplicate the item, and start with 1 */ duplicate the item, and start with 1 */
size_t length = strlen(item->value); size_t length = strlen(item->value);
struct slot **slot_p = TagPoolSlot **slot_p =
&slots[calc_hash_n(item->type, item->value, &slots[calc_hash_n(item->type, item->value,
length) % NUM_SLOTS]; length) % NUM_SLOTS];
slot = slot_alloc(*slot_p, item->type, slot = slot_alloc(*slot_p, item->type,
@ -136,7 +135,7 @@ tag_pool_dup_item(TagItem *item)
void void
tag_pool_put_item(TagItem *item) tag_pool_put_item(TagItem *item)
{ {
struct slot **slot_p, *slot; TagPoolSlot **slot_p, *slot;
slot = tag_item_to_slot(item); slot = tag_item_to_slot(item);
assert(slot->ref > 0); assert(slot->ref > 0);