diff options
author | Max Kellermann <max@musicpd.org> | 2017-12-20 14:43:29 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-12-20 15:02:14 +0100 |
commit | 25fa3ccade6aa9ab0d03c58ffbe8fee4945a3a3c (patch) | |
tree | 38e1c77cf073a21e6ea7ef4f077b185635461c61 /src | |
parent | c6a95395b57e6925d683339c969fa43d2f6b48e3 (diff) |
MusicChunk, player/Thread: use std::unique_ptr<Tag>
Diffstat (limited to 'src')
-rw-r--r-- | src/MusicChunk.cxx | 6 | ||||
-rw-r--r-- | src/MusicChunk.hxx | 14 | ||||
-rw-r--r-- | src/decoder/Bridge.cxx | 2 | ||||
-rw-r--r-- | src/output/Source.cxx | 2 | ||||
-rw-r--r-- | src/player/Thread.cxx | 13 | ||||
-rw-r--r-- | src/tag/Tag.cxx | 10 | ||||
-rw-r--r-- | src/tag/Tag.hxx | 4 |
7 files changed, 21 insertions, 30 deletions
diff --git a/src/MusicChunk.cxx b/src/MusicChunk.cxx index 581974ae4..9f33e9af5 100644 --- a/src/MusicChunk.cxx +++ b/src/MusicChunk.cxx @@ -24,10 +24,8 @@ #include <assert.h> -MusicChunk::~MusicChunk() -{ - delete tag; -} +MusicChunk::MusicChunk() noexcept = default; +MusicChunk::~MusicChunk() noexcept = default; #ifndef NDEBUG bool diff --git a/src/MusicChunk.hxx b/src/MusicChunk.hxx index a730a0b2d..394366308 100644 --- a/src/MusicChunk.hxx +++ b/src/MusicChunk.hxx @@ -28,6 +28,8 @@ #include "AudioFormat.hxx" #endif +#include <memory> + #include <stdint.h> #include <stddef.h> @@ -67,11 +69,9 @@ struct MusicChunk { /** * An optional tag associated with this chunk (and the - * following chunks); appears at song boundaries. The tag - * object is owned by this chunk, and must be freed when this - * chunk is deinitialized. + * following chunks); appears at song boundaries. */ - Tag *tag = nullptr; + std::unique_ptr<Tag> tag; /** * Replay gain information associated with this chunk. @@ -101,12 +101,10 @@ struct MusicChunk { AudioFormat audio_format; #endif - MusicChunk() = default; + MusicChunk() noexcept; + ~MusicChunk() noexcept; MusicChunk(const MusicChunk &) = delete; - - ~MusicChunk(); - MusicChunk &operator=(const MusicChunk &) = delete; bool IsEmpty() const { diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx index 857fd32c1..0bd6d9e1c 100644 --- a/src/decoder/Bridge.cxx +++ b/src/decoder/Bridge.cxx @@ -215,7 +215,7 @@ DecoderBridge::DoSendTag(const Tag &tag) return dc.command; } - chunk->tag = new Tag(tag); + chunk->tag = std::make_unique<Tag>(tag); return DecoderCommand::NONE; } diff --git a/src/output/Source.cxx b/src/output/Source.cxx index 4bfad46a6..15c63b1da 100644 --- a/src/output/Source.cxx +++ b/src/output/Source.cxx @@ -222,7 +222,7 @@ AudioOutputSource::Fill(Mutex &mutex) if (current_chunk == nullptr) return false; - pending_tag = current_chunk->tag; + pending_tag = current_chunk->tag.get(); try { /* release the mutex while the filter runs, because diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 6ffa3d128..eeb406fce 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -131,7 +131,7 @@ class Player { * postponed, and sent to the output thread when the new song * really begins. */ - Tag *cross_fade_tag = nullptr; + std::unique_ptr<Tag> cross_fade_tag; /** * The current audio format for the audio outputs. @@ -837,10 +837,8 @@ Player::PlayNextChunk() noexcept /* don't send the tags of the new song (which is being faded in) yet; postpone it until the current song is faded out */ - cross_fade_tag = - Tag::MergeReplace(cross_fade_tag, - other_chunk->tag); - other_chunk->tag = nullptr; + cross_fade_tag = Tag::Merge(std::move(cross_fade_tag), + std::move(other_chunk->tag)); if (pc.cross_fade.mixramp_delay <= 0) { chunk->mix_ratio = ((float)cross_fade_position) @@ -889,7 +887,8 @@ Player::PlayNextChunk() noexcept /* insert the postponed tag if cross-fading is finished */ if (xfade_state != CrossFadeState::ACTIVE && cross_fade_tag != nullptr) { - chunk->tag = Tag::MergeReplace(chunk->tag, cross_fade_tag); + chunk->tag = Tag::Merge(std::move(chunk->tag), + std::move(cross_fade_tag)); cross_fade_tag = nullptr; } @@ -1114,7 +1113,7 @@ Player::Run() noexcept ClearAndDeletePipe(); - delete cross_fade_tag; + cross_fade_tag.reset(); if (song != nullptr) { FormatDefault(player_domain, "played \"%s\"", song->GetURI()); diff --git a/src/tag/Tag.cxx b/src/tag/Tag.cxx index 7fba27b09..4bf4751bd 100644 --- a/src/tag/Tag.cxx +++ b/src/tag/Tag.cxx @@ -63,8 +63,8 @@ Tag::Merge(const Tag &base, const Tag &add) noexcept return builder.CommitNew(); } -Tag * -Tag::MergeReplace(Tag *base, Tag *add) +std::unique_ptr<Tag> +Tag::Merge(std::unique_ptr<Tag> base, std::unique_ptr<Tag> add) { if (add == nullptr) return base; @@ -72,11 +72,7 @@ Tag::MergeReplace(Tag *base, Tag *add) if (base == nullptr) return add; - Tag *tag = Merge(*base, *add).release(); - delete base; - delete add; - - return tag; + return Merge(*base, *add); } const char * diff --git a/src/tag/Tag.hxx b/src/tag/Tag.hxx index d5cc3c030..624a92a35 100644 --- a/src/tag/Tag.hxx +++ b/src/tag/Tag.hxx @@ -126,8 +126,8 @@ struct Tag { * * @return a newly allocated tag */ - gcc_malloc gcc_returns_nonnull - static Tag *MergeReplace(Tag *base, Tag *add); + static std::unique_ptr<Tag> Merge(std::unique_ptr<Tag> base, + std::unique_ptr<Tag> add); /** * Returns the first value of the specified tag type, or |