aboutsummaryrefslogtreecommitdiffstats
path: root/src/tag
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-02-06 12:25:34 +0100
committerMax Kellermann <max@duempel.org>2015-02-06 12:25:34 +0100
commitb3fe3e8b3de5794762f21000d5771b0491e8a041 (patch)
tree327f310b6e160bf37e765233ae0cfe85e3687a03 /src/tag
parent8a6b4db19f63f95a7167ca27026cb16aa80fffad (diff)
downloadmpd-b3fe3e8b3de5794762f21000d5771b0491e8a041.tar.gz
mpd-b3fe3e8b3de5794762f21000d5771b0491e8a041.tar.xz
mpd-b3fe3e8b3de5794762f21000d5771b0491e8a041.zip
TagBuilder: allow adding duplicate tag types in Complement()
Build a table of pre-existing tag types before adding new items. The old way would check HasType() each time, which would return true after the first instance of that tag type had been added, preventing duplicate tag types to be merged. This broke duplicate tag types loaded from the state file, because this code path uses TagBuilder::Complement().
Diffstat (limited to 'src/tag')
-rw-r--r--src/tag/TagBuilder.cxx11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/tag/TagBuilder.cxx b/src/tag/TagBuilder.cxx
index 93518f6e9..0882f9561 100644
--- a/src/tag/TagBuilder.cxx
+++ b/src/tag/TagBuilder.cxx
@@ -25,6 +25,8 @@
#include "Tag.hxx"
#include "util/WritableBuffer.hxx"
+#include <array>
+
#include <assert.h>
#include <string.h>
#include <stdlib.h>
@@ -168,12 +170,19 @@ TagBuilder::Complement(const Tag &other)
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<bool, TAG_NUM_OF_ITEM_TYPES> present;
+ present.fill(false);
+ for (const TagItem *i : items)
+ present[i->type] = true;
+
items.reserve(items.size() + other.num_items);
tag_pool_lock.lock();
for (unsigned i = 0, n = other.num_items; i != n; ++i) {
TagItem *item = other.items[i];
- if (!HasType(item->type))
+ if (!present[item->type])
items.push_back(tag_pool_dup_item(item));
}
tag_pool_lock.unlock();