From cbd38327e7f6948647768227ac4836f64e5ccd51 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 31 Jul 2013 00:34:22 +0200 Subject: DecoderAPI: pass rvalue reference to decoder_tag() Avoid duplicating the tag. --- src/DecoderAPI.cxx | 7 +++---- src/DecoderAPI.hxx | 3 +-- src/decoder/FlacDecoderPlugin.cxx | 2 +- src/decoder/MadDecoderPlugin.cxx | 5 +++-- src/decoder/OpusDecoderPlugin.cxx | 2 +- src/decoder/VorbisDecoderPlugin.cxx | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx index c7a12c68a..a4bdf37c4 100644 --- a/src/DecoderAPI.cxx +++ b/src/DecoderAPI.cxx @@ -471,19 +471,18 @@ decoder_data(struct decoder *decoder, enum decoder_command decoder_tag(G_GNUC_UNUSED struct decoder *decoder, struct input_stream *is, - const Tag *tag) + Tag &&tag) { G_GNUC_UNUSED const struct decoder_control *dc = decoder->dc; enum decoder_command cmd; assert(dc->state == DECODE_STATE_DECODE); assert(dc->pipe != NULL); - assert(tag != NULL); /* save the tag */ delete decoder->decoder_tag; - decoder->decoder_tag = new Tag(*tag); + decoder->decoder_tag = new Tag(tag); /* check for a new stream tag */ @@ -509,7 +508,7 @@ decoder_tag(G_GNUC_UNUSED struct decoder *decoder, struct input_stream *is, delete merged; } else /* send only the decoder tag */ - cmd = do_send_tag(decoder, *tag); + cmd = do_send_tag(decoder, *decoder->decoder_tag); return cmd; } diff --git a/src/DecoderAPI.hxx b/src/DecoderAPI.hxx index d4886d062..c70365bff 100644 --- a/src/DecoderAPI.hxx +++ b/src/DecoderAPI.hxx @@ -141,8 +141,7 @@ decoder_data(struct decoder *decoder, struct input_stream *is, * command pending */ enum decoder_command -decoder_tag(struct decoder *decoder, struct input_stream *is, - const Tag *tag); +decoder_tag(struct decoder *decoder, struct input_stream *is, Tag &&tag); /** * Set replay gain values for the following chunks. diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx index 3bc50aa4e..4140d14f7 100644 --- a/src/decoder/FlacDecoderPlugin.cxx +++ b/src/decoder/FlacDecoderPlugin.cxx @@ -174,7 +174,7 @@ flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec, while (true) { if (data->tag != nullptr && !data->tag->IsEmpty()) { cmd = decoder_tag(data->decoder, data->input_stream, - data->tag); + std::move(*data->tag)); delete data->tag; data->tag = new Tag(); } else diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx index 9f36fd86b..b75e12343 100644 --- a/src/decoder/MadDecoderPlugin.cxx +++ b/src/decoder/MadDecoderPlugin.cxx @@ -1084,7 +1084,8 @@ MadDecoder::Read() ret = DecodeNextFrameHeader(&tag); if (tag != nullptr) { - decoder_tag(decoder, input_stream, tag); + decoder_tag(decoder, input_stream, + std::move(*tag)); delete tag; } } while (ret == DECODE_CONT); @@ -1142,7 +1143,7 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) data.total_time); if (tag != nullptr) { - decoder_tag(decoder, input_stream, tag); + decoder_tag(decoder, input_stream, std::move(*tag)); delete tag; } diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx index 148125347..08c67b570 100644 --- a/src/decoder/OpusDecoderPlugin.cxx +++ b/src/decoder/OpusDecoderPlugin.cxx @@ -228,7 +228,7 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet) if (ScanOpusTags(packet.packet, packet.bytes, &add_tag_handler, &tag) && !tag.IsEmpty()) - cmd = decoder_tag(decoder, input_stream, &tag); + cmd = decoder_tag(decoder, input_stream, std::move(tag)); else cmd = decoder_get_command(decoder); diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx index 36b3e3139..68d5a21f0 100644 --- a/src/decoder/VorbisDecoderPlugin.cxx +++ b/src/decoder/VorbisDecoderPlugin.cxx @@ -158,7 +158,7 @@ vorbis_send_comments(struct decoder *decoder, struct input_stream *is, if (!tag) return; - decoder_tag(decoder, is, tag); + decoder_tag(decoder, is, std::move(*tag)); delete tag; } -- cgit v1.2.3