IcyMetaDataParser: return std::unique_ptr<Tag>

This commit is contained in:
Max Kellermann 2017-12-20 15:06:33 +01:00
parent 6b77ee9a5e
commit 99f4bce112
3 changed files with 11 additions and 13 deletions

View File

@ -39,7 +39,7 @@ IcyMetaDataParser::Reset() noexcept
if (data_rest == 0 && meta_size > 0)
delete[] meta_data;
delete tag;
tag.reset();
data_rest = data_size;
meta_size = 0;
@ -209,9 +209,7 @@ IcyMetaDataParser::Meta(const void *data, size_t length) noexcept
if (meta_position == meta_size) {
/* parse */
delete tag;
tag = icy_parse_tag(meta_data, meta_data + meta_size).release();
tag = icy_parse_tag(meta_data, meta_data + meta_size);
delete[] meta_data;
/* change back to normal data mode */

View File

@ -20,9 +20,11 @@
#ifndef MPD_ICY_META_DATA_PARSER_HXX
#define MPD_ICY_META_DATA_PARSER_HXX
#include <stddef.h>
#include "tag/Tag.hxx"
struct Tag;
#include <memory>
#include <stddef.h>
class IcyMetaDataParser {
size_t data_size = 0, data_rest;
@ -30,7 +32,7 @@ class IcyMetaDataParser {
size_t meta_size, meta_position;
char *meta_data;
Tag *tag;
std::unique_ptr<Tag> tag;
public:
~IcyMetaDataParser() noexcept {
@ -81,10 +83,8 @@ public:
*/
size_t ParseInPlace(void *data, size_t length) noexcept;
Tag *ReadTag() noexcept {
Tag *result = tag;
tag = nullptr;
return result;
std::unique_ptr<Tag> ReadTag() noexcept {
return std::exchange(tag, nullptr);
}
};

View File

@ -55,10 +55,10 @@ IcyInputStream::ReadTag()
input_tag = new_input_tag;
}
Tag *new_icy_tag = parser.ReadTag();
auto new_icy_tag = parser.ReadTag();
if (new_icy_tag != nullptr) {
delete icy_tag;
icy_tag = new_icy_tag;
icy_tag = new_icy_tag.release();
}
if (new_input_tag == nullptr && new_icy_tag == nullptr)