aboutsummaryrefslogtreecommitdiffstats
path: root/src/tag
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-09-05 19:11:50 +0200
committerMax Kellermann <max@duempel.org>2013-09-26 17:35:08 +0200
commit52ee132d92d4a04d31bbbdeb7c6c0077bd2a2828 (patch)
tree098cf4f9385693b28e41c5342fcdfae416b058dd /src/tag
parent7ca0aedcfc35c784d7ae07cd1f1e8dce684e5901 (diff)
downloadmpd-52ee132d92d4a04d31bbbdeb7c6c0077bd2a2828.tar.gz
mpd-52ee132d92d4a04d31bbbdeb7c6c0077bd2a2828.tar.xz
mpd-52ee132d92d4a04d31bbbdeb7c6c0077bd2a2828.zip
TagHandler: use a TagBuilder internally
Reduce heap allocator overhead.
Diffstat (limited to 'src/tag')
-rw-r--r--src/tag/TagHandler.cxx14
-rw-r--r--src/tag/TagHandler.hxx4
-rw-r--r--src/tag/TagId3.cxx16
3 files changed, 15 insertions, 19 deletions
diff --git a/src/tag/TagHandler.cxx b/src/tag/TagHandler.cxx
index 055fae49a..859f92b20 100644
--- a/src/tag/TagHandler.cxx
+++ b/src/tag/TagHandler.cxx
@@ -19,24 +19,24 @@
#include "config.h"
#include "TagHandler.hxx"
-#include "Tag.hxx"
+#include "TagBuilder.hxx"
#include <glib.h>
static void
add_tag_duration(unsigned seconds, void *ctx)
{
- Tag *tag = (Tag *)ctx;
+ TagBuilder &tag = *(TagBuilder *)ctx;
- tag->time = seconds;
+ tag.SetTime(seconds);
}
static void
add_tag_tag(enum tag_type type, const char *value, void *ctx)
{
- Tag *tag = (Tag *)ctx;
+ TagBuilder &tag = *(TagBuilder *)ctx;
- tag->AddItem(type, value);
+ tag.AddItem(type, value);
}
const struct tag_handler add_tag_handler = {
@@ -48,10 +48,10 @@ const struct tag_handler add_tag_handler = {
static void
full_tag_pair(const char *name, gcc_unused const char *value, void *ctx)
{
- Tag *tag = (Tag *)ctx;
+ TagBuilder &tag = *(TagBuilder *)ctx;
if (g_ascii_strcasecmp(name, "cuesheet") == 0)
- tag->has_playlist = true;
+ tag.SetHasPlaylist(true);
}
const struct tag_handler full_tag_handler = {
diff --git a/src/tag/TagHandler.hxx b/src/tag/TagHandler.hxx
index 3303dd27e..36871c962 100644
--- a/src/tag/TagHandler.hxx
+++ b/src/tag/TagHandler.hxx
@@ -86,13 +86,13 @@ tag_handler_invoke_pair(const struct tag_handler *handler, void *ctx,
}
/**
- * This #tag_handler implementation adds tag values to a #tag object
+ * This #tag_handler implementation adds tag values to a #TagBuilder object
* (casted from the context pointer).
*/
extern const struct tag_handler add_tag_handler;
/**
- * This #tag_handler implementation adds tag values to a #tag object
+ * This #tag_handler implementation adds tag values to a #TagBuilder object
* (casted from the context pointer), and supports the has_playlist
* attribute.
*/
diff --git a/src/tag/TagId3.cxx b/src/tag/TagId3.cxx
index 0bea92bb7..0fc1b01db 100644
--- a/src/tag/TagId3.cxx
+++ b/src/tag/TagId3.cxx
@@ -22,6 +22,7 @@
#include "TagHandler.hxx"
#include "TagTable.hxx"
#include "Tag.hxx"
+#include "TagBuilder.hxx"
#include "util/Error.hxx"
#include "ConfigGlobal.hxx"
@@ -387,16 +388,11 @@ scan_id3_tag(struct id3_tag *tag,
Tag *
tag_id3_import(struct id3_tag *tag)
{
- Tag *ret = new Tag();
-
- scan_id3_tag(tag, &add_tag_handler, ret);
-
- if (ret->IsEmpty()) {
- delete ret;
- ret = nullptr;
- }
-
- return ret;
+ TagBuilder tag_builder;
+ scan_id3_tag(tag, &add_tag_handler, &tag_builder);
+ return tag_builder.IsEmpty()
+ ? nullptr
+ : tag_builder.Commit();
}
static int