diff options
author | Max Kellermann <max@duempel.org> | 2013-12-03 12:56:36 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-03 12:59:55 +0100 |
commit | 9f4e96fdfa0967fa83444a44c8e6fdbda14b96c3 (patch) | |
tree | 2f08a42a9c2f70160e892314dbeaf3bf559a8203 /src/tag | |
parent | c36af357303891a45fdcb286b99ca8bb5be20693 (diff) | |
download | mpd-9f4e96fdfa0967fa83444a44c8e6fdbda14b96c3.tar.gz mpd-9f4e96fdfa0967fa83444a44c8e6fdbda14b96c3.tar.xz mpd-9f4e96fdfa0967fa83444a44c8e6fdbda14b96c3.zip |
PaylistTag: use class TagBuilder
Diffstat (limited to 'src/tag')
-rw-r--r-- | src/tag/Tag.cxx | 20 | ||||
-rw-r--r-- | src/tag/Tag.hxx | 12 | ||||
-rw-r--r-- | src/tag/TagBuilder.cxx | 34 | ||||
-rw-r--r-- | src/tag/TagBuilder.hxx | 10 |
4 files changed, 37 insertions, 39 deletions
diff --git a/src/tag/Tag.cxx b/src/tag/Tag.cxx index 7d1da63df..43ded308a 100644 --- a/src/tag/Tag.cxx +++ b/src/tag/Tag.cxx @@ -187,23 +187,3 @@ Tag::AddItem(TagType type, const char *value) { AddItem(type, value, strlen(value)); } - -void -Tag::RemoveType(TagType type) -{ - auto dest = items, src = items, end = items + num_items; - - tag_pool_lock.lock(); - while (src != end) { - TagItem *item = *src++; - if (item->type == type) - /* remove it */ - tag_pool_put_item(item); - else - /* keep it */ - *dest++ = item; - } - tag_pool_lock.unlock(); - - num_items = dest - items; -} diff --git a/src/tag/Tag.hxx b/src/tag/Tag.hxx index 0e48298a7..e404a4f26 100644 --- a/src/tag/Tag.hxx +++ b/src/tag/Tag.hxx @@ -122,18 +122,6 @@ struct Tag { void AddItem(TagType type, const char *value); /** - * Removes all tag items. - */ - void RemoveAll() { - num_items = 0; - } - - /** - * Removes all tag items of the specified type. - */ - void RemoveType(TagType type); - - /** * Merges the data from two tags. If both tags share data for the * same TagType, only data from "add" is used. * diff --git a/src/tag/TagBuilder.cxx b/src/tag/TagBuilder.cxx index 2d3b49eb5..5c7da2a1a 100644 --- a/src/tag/TagBuilder.cxx +++ b/src/tag/TagBuilder.cxx @@ -108,13 +108,7 @@ TagBuilder::Clear() { time = -1; has_playlist = false; - - tag_pool_lock.lock(); - for (auto i : items) - tag_pool_put_item(i); - tag_pool_lock.unlock(); - - items.clear(); + RemoveAll(); } void @@ -216,3 +210,29 @@ TagBuilder::AddItem(TagType type, const char *value) AddItem(type, value, strlen(value)); } + +void +TagBuilder::RemoveAll() +{ + tag_pool_lock.lock(); + for (auto i : items) + tag_pool_put_item(i); + tag_pool_lock.unlock(); + + items.clear(); +} + +void +TagBuilder::RemoveType(TagType type) +{ + const auto begin = items.begin(), end = items.end(); + + items.erase(std::remove_if(begin, end, + [type](TagItem *item) { + if (item->type != type) + return false; + tag_pool_put_item(item); + return true; + }), + end); +} diff --git a/src/tag/TagBuilder.hxx b/src/tag/TagBuilder.hxx index cd4fa4e57..fe647db08 100644 --- a/src/tag/TagBuilder.hxx +++ b/src/tag/TagBuilder.hxx @@ -147,6 +147,16 @@ public: gcc_nonnull_all void AddItem(TagType type, const char *value); + /** + * Removes all tag items. + */ + void RemoveAll(); + + /** + * Removes all tag items of the specified type. + */ + void RemoveType(TagType type); + private: gcc_nonnull_all void AddItemInternal(TagType type, const char *value, size_t length); |