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/SongUpdate.cxx | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/SongUpdate.cxx') diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx index 8e9768d55..4c5f35c78 100644 --- a/src/SongUpdate.cxx +++ b/src/SongUpdate.cxx @@ -29,6 +29,7 @@ #include "DecoderPlugin.hxx" #include "DecoderList.hxx" #include "tag/Tag.hxx" +#include "tag/TagBuilder.hxx" #include "tag/TagHandler.hxx" #include "tag/TagId3.hxx" #include "tag/ApeTag.hxx" @@ -113,15 +114,15 @@ Song::UpdateFile() Mutex mutex; Cond cond; + TagBuilder tag_builder; + do { /* load file tag */ - tag = new Tag(); if (decoder_plugin_scan_file(plugin, path_fs.c_str(), - &full_tag_handler, tag)) + &full_tag_handler, &tag_builder)) break; - delete tag; - tag = nullptr; + tag_builder.Clear(); /* fall back to stream tag */ if (plugin->scan_stream != NULL) { @@ -134,14 +135,12 @@ Song::UpdateFile() /* now try the stream_tag() method */ if (is != NULL) { - tag = new Tag(); if (decoder_plugin_scan_stream(plugin, is, &full_tag_handler, - tag)) + &tag_builder)) break; - delete tag; - tag = nullptr; + tag_builder.Clear(); is->LockSeek(0, SEEK_SET, IgnoreError()); } @@ -153,10 +152,15 @@ Song::UpdateFile() if (is != NULL) is->Close(); - if (tag != nullptr && tag->IsEmpty()) - tag_scan_fallback(path_fs.c_str(), &full_tag_handler, tag); + if (!tag_builder.IsDefined()) + return false; + + if (tag_builder.IsEmpty()) + tag_scan_fallback(path_fs.c_str(), &full_tag_handler, + &tag_builder); - return tag != nullptr; + tag = tag_builder.Commit(); + return true; } bool -- cgit v1.2.3