tag/Builder: do not acquire tag_pool_lock if TagItem list is empty
This commit is contained in:
parent
96875921b7
commit
bde64a13e2
|
@ -36,10 +36,12 @@ TagBuilder::TagBuilder(const Tag &other) noexcept
|
||||||
{
|
{
|
||||||
items.reserve(other.num_items);
|
items.reserve(other.num_items);
|
||||||
|
|
||||||
|
const std::size_t n = other.num_items;
|
||||||
|
if (n > 0) {
|
||||||
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
||||||
|
for (std::size_t i = 0; i != n; ++i)
|
||||||
for (unsigned i = 0, n = other.num_items; i != n; ++i)
|
|
||||||
items.push_back(tag_pool_dup_item(other.items[i]));
|
items.push_back(tag_pool_dup_item(other.items[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TagBuilder::TagBuilder(Tag &&other) noexcept
|
TagBuilder::TagBuilder(Tag &&other) noexcept
|
||||||
|
@ -65,12 +67,15 @@ TagBuilder::operator=(const TagBuilder &other) noexcept
|
||||||
has_playlist = other.has_playlist;
|
has_playlist = other.has_playlist;
|
||||||
|
|
||||||
RemoveAll();
|
RemoveAll();
|
||||||
|
|
||||||
|
if (!other.items.empty()) {
|
||||||
items = other.items;
|
items = other.items;
|
||||||
|
|
||||||
/* increment the tag pool refcounters */
|
/* increment the tag pool refcounters */
|
||||||
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
||||||
for (auto &i : items)
|
for (auto &i : items)
|
||||||
i = tag_pool_dup_item(i);
|
i = tag_pool_dup_item(i);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -181,12 +186,15 @@ TagBuilder::Complement(const Tag &other) noexcept
|
||||||
|
|
||||||
items.reserve(items.size() + other.num_items);
|
items.reserve(items.size() + other.num_items);
|
||||||
|
|
||||||
|
const std::size_t n = other.num_items;
|
||||||
|
if (n > 0) {
|
||||||
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
||||||
for (unsigned i = 0, n = other.num_items; i != n; ++i) {
|
for (std::size_t i = 0; i != n; ++i) {
|
||||||
TagItem *item = other.items[i];
|
TagItem *item = other.items[i];
|
||||||
if (!present[item->type])
|
if (!present[item->type])
|
||||||
items.push_back(tag_pool_dup_item(item));
|
items.push_back(tag_pool_dup_item(item));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -245,6 +253,11 @@ TagBuilder::AddEmptyItem(TagType type) noexcept
|
||||||
void
|
void
|
||||||
TagBuilder::RemoveAll() noexcept
|
TagBuilder::RemoveAll() noexcept
|
||||||
{
|
{
|
||||||
|
if (items.empty())
|
||||||
|
/* don't acquire the tag_pool_lock if we're not going
|
||||||
|
to call tag_pool_put_item() anyway */
|
||||||
|
return;
|
||||||
|
|
||||||
{
|
{
|
||||||
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
||||||
for (auto i : items)
|
for (auto i : items)
|
||||||
|
|
Loading…
Reference in New Issue