TagHandler: use a TagBuilder internally
Reduce heap allocator overhead.
This commit is contained in:
@@ -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 = {
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user