From f1285a6dfd7abac5e2151040d9edbc70ed4e9dba Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Mar 2016 08:07:22 +0100 Subject: [PATCH] tag/TagPool: add constexpr MAX_REF --- src/tag/TagPool.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tag/TagPool.cxx b/src/tag/TagPool.cxx index dc8cc5551..55655cb54 100644 --- a/src/tag/TagPool.cxx +++ b/src/tag/TagPool.cxx @@ -23,6 +23,8 @@ #include "util/Cast.hxx" #include "util/VarSize.hxx" +#include + #include #include #include @@ -36,6 +38,8 @@ struct TagPoolSlot { unsigned char ref; TagItem item; + static constexpr unsigned MAX_REF = std::numeric_limits::max(); + TagPoolSlot(TagPoolSlot *_next, TagType type, const char *value, size_t length) :next(_next), ref(1) { @@ -116,7 +120,7 @@ tag_pool_get_item(TagType type, const char *value, size_t length) if (slot->item.type == type && length == strlen(slot->item.value) && memcmp(value, slot->item.value, length) == 0 && - slot->ref < 0xff) { + slot->ref < TagPoolSlot::MAX_REF) { assert(slot->ref > 0); ++slot->ref; return &slot->item; @@ -135,11 +139,11 @@ tag_pool_dup_item(TagItem *item) assert(slot->ref > 0); - if (slot->ref < 0xff) { + if (slot->ref < TagPoolSlot::MAX_REF) { ++slot->ref; return item; } else { - /* the reference counter overflows above 0xff; + /* the reference counter overflows above MAX_REF; duplicate the item, and start with 1 */ size_t length = strlen(item->value); auto slot_p = tag_value_slot_p(item->type,