From 2da847dd30bcbb4dc1aad74b1d02df2496ce73e3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 29 Jun 2022 16:49:31 +0200 Subject: [PATCH] tag/Pool: use std::string_view instead of StringView --- src/tag/Pool.cxx | 20 +++++++++----------- src/tag/Pool.hxx | 5 +++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/tag/Pool.cxx b/src/tag/Pool.cxx index e5a6d57f2..6451dcab4 100644 --- a/src/tag/Pool.cxx +++ b/src/tag/Pool.cxx @@ -21,7 +21,6 @@ #include "Item.hxx" #include "util/Cast.hxx" #include "util/VarSize.hxx" -#include "util/StringView.hxx" #include #include @@ -42,24 +41,23 @@ struct TagPoolSlot { static constexpr unsigned MAX_REF = std::numeric_limits::max(); TagPoolSlot(TagPoolSlot *_next, TagType type, - StringView value) noexcept + std::string_view value) noexcept :next(_next) { item.type = type; - memcpy(item.value, value.data, value.size); - item.value[value.size] = 0; + *std::copy(value.begin(), value.end(), item.value) = 0; } static TagPoolSlot *Create(TagPoolSlot *_next, TagType type, - StringView value) noexcept; + std::string_view value) noexcept; }; TagPoolSlot * TagPoolSlot::Create(TagPoolSlot *_next, TagType type, - StringView value) noexcept + std::string_view value) noexcept { TagPoolSlot *dummy; return NewVarSize(sizeof(dummy->item.value), - value.size + 1, + value.size() + 1, _next, type, value); } @@ -67,7 +65,7 @@ TagPoolSlot::Create(TagPoolSlot *_next, TagType type, static TagPoolSlot *slots[NUM_SLOTS]; static inline unsigned -calc_hash(TagType type, StringView p) noexcept +calc_hash(TagType type, std::string_view p) noexcept { unsigned hash = 5381; @@ -97,7 +95,7 @@ tag_item_to_slot(TagItem *item) noexcept } static inline TagPoolSlot ** -tag_value_slot_p(TagType type, StringView value) noexcept +tag_value_slot_p(TagType type, std::string_view value) noexcept { return &slots[calc_hash(type, value) % NUM_SLOTS]; } @@ -109,12 +107,12 @@ tag_value_slot_p(TagType type, const char *value) noexcept } TagItem * -tag_pool_get_item(TagType type, StringView value) noexcept +tag_pool_get_item(TagType type, std::string_view value) noexcept { auto slot_p = tag_value_slot_p(type, value); for (auto slot = *slot_p; slot != nullptr; slot = slot->next) { if (slot->item.type == type && - value.Equals(slot->item.value) && + value == slot->item.value && slot->ref < TagPoolSlot::MAX_REF) { assert(slot->ref > 0); ++slot->ref; diff --git a/src/tag/Pool.hxx b/src/tag/Pool.hxx index 9ec9ab0cb..0e7e73bc0 100644 --- a/src/tag/Pool.hxx +++ b/src/tag/Pool.hxx @@ -23,14 +23,15 @@ #include "Type.h" #include "thread/Mutex.hxx" +#include + extern Mutex tag_pool_lock; struct TagItem; -struct StringView; [[nodiscard]] TagItem * -tag_pool_get_item(TagType type, StringView value) noexcept; +tag_pool_get_item(TagType type, std::string_view value) noexcept; [[nodiscard]] TagItem *