From a24589d46e822975fcd81a72a3d29d3c3e340277 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 5 Sep 2013 19:23:06 +0200 Subject: TagBuilder: add method Commit(Tag&) For callers that already have a Tag instance. --- src/tag/TagBuilder.cxx | 23 +++++++++++++++-------- src/tag/TagBuilder.hxx | 6 ++++++ 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src/tag') diff --git a/src/tag/TagBuilder.cxx b/src/tag/TagBuilder.cxx index d1babdadb..23409fe33 100644 --- a/src/tag/TagBuilder.cxx +++ b/src/tag/TagBuilder.cxx @@ -43,27 +43,34 @@ TagBuilder::Clear() items.clear(); } -Tag * -TagBuilder::Commit() +void +TagBuilder::Commit(Tag &tag) { - Tag *tag = new Tag(); - tag->time = time; - tag->has_playlist = has_playlist; + tag.Clear(); + + tag.time = time; + tag.has_playlist = has_playlist; /* move all TagItem pointers to the new Tag object without touching the TagPool reference counters; the vector::clear() call is important to detach them from this object */ const unsigned n_items = items.size(); - tag->num_items = n_items; - tag->items = g_new(TagItem *, n_items); - std::copy_n(items.begin(), n_items, tag->items); + tag.num_items = n_items; + tag.items = g_new(TagItem *, n_items); + std::copy_n(items.begin(), n_items, tag.items); items.clear(); /* now ensure that this object is fresh (will not delete any items because we've already moved them out) */ Clear(); +} +Tag * +TagBuilder::Commit() +{ + Tag *tag = new Tag(); + Commit(*tag); return tag; } diff --git a/src/tag/TagBuilder.hxx b/src/tag/TagBuilder.hxx index 4eeb0c48d..63a14a946 100644 --- a/src/tag/TagBuilder.hxx +++ b/src/tag/TagBuilder.hxx @@ -83,6 +83,12 @@ public: void Clear(); + /** + * Move this object to the given #Tag instance. This object + * is empty afterwards. + */ + void Commit(Tag &tag); + /** * Create a new #Tag instance from data in this object. The * returned object is owned by the caller. This object is -- cgit v1.2.3