From 52ee132d92d4a04d31bbbdeb7c6c0077bd2a2828 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 5 Sep 2013 19:11:50 +0200 Subject: TagHandler: use a TagBuilder internally Reduce heap allocator overhead. --- src/tag/TagHandler.cxx | 14 +++++++------- src/tag/TagHandler.hxx | 4 ++-- src/tag/TagId3.cxx | 16 ++++++---------- 3 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src/tag') 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 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 -- cgit v1.2.3