From a1359f23883b17ff86cebcf33e3dd489fa50800e Mon Sep 17 00:00:00 2001 From: gd Date: Tue, 1 Nov 2022 17:53:22 +0200 Subject: [PATCH] TagBuilder: skip unnecessary preperation if there are no items to add --- src/tag/Builder.cxx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/tag/Builder.cxx b/src/tag/Builder.cxx index 0a38c4853..72dbd8eff 100644 --- a/src/tag/Builder.cxx +++ b/src/tag/Builder.cxx @@ -33,10 +33,9 @@ TagBuilder::TagBuilder(const Tag &other) noexcept :duration(other.duration), has_playlist(other.has_playlist) { - items.reserve(other.num_items); - const std::size_t n = other.num_items; if (n > 0) { + items.reserve(other.num_items); const std::scoped_lock protect(tag_pool_lock); for (std::size_t i = 0; i != n; ++i) items.push_back(tag_pool_dup_item(other.items[i])); @@ -176,17 +175,17 @@ TagBuilder::Complement(const Tag &other) noexcept has_playlist |= other.has_playlist; - /* build a table of tag types that were already present in - this object, which will not be copied from #other */ - std::array present; - present.fill(false); - for (const TagItem *i : items) - present[i->type] = true; - - items.reserve(items.size() + other.num_items); - const std::size_t n = other.num_items; if (n > 0) { + /* build a table of tag types that were already present in + this object, which will not be copied from #other */ + std::array present; + present.fill(false); + for (const TagItem *i : items) + present[i->type] = true; + + items.reserve(items.size() + n); + const std::scoped_lock protect(tag_pool_lock); for (std::size_t i = 0; i != n; ++i) { TagItem *item = other.items[i];