From 5e0117b4441f257fcb1aab48b42a787567ebcbe6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 14 Feb 2010 20:36:31 +0100 Subject: replay_gain_info: allocate the struct statically Don't allocate each replay_gain_info object on the heap. Those objects who held a pointer now store a full replay_gain_info object. This reduces the number of allocations and heap fragmentation. --- src/decoder/mad_decoder_plugin.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'src/decoder/mad_decoder_plugin.c') diff --git a/src/decoder/mad_decoder_plugin.c b/src/decoder/mad_decoder_plugin.c index 87dfbeabd..379cb9b8a 100644 --- a/src/decoder/mad_decoder_plugin.c +++ b/src/decoder/mad_decoder_plugin.c @@ -300,17 +300,17 @@ static int parse_rva2(struct id3_tag * tag, struct replay_gain_info * replay_gai #endif #ifdef HAVE_ID3TAG -static struct replay_gain_info * -parse_id3_replay_gain_info(struct id3_tag *tag) +static bool +parse_id3_replay_gain_info(struct replay_gain_info *replay_gain_info, + struct id3_tag *tag) { int i; char *key; char *value; struct id3_frame *frame; bool found = false; - struct replay_gain_info *replay_gain_info; - replay_gain_info = replay_gain_info_new(); + replay_gain_info_init(replay_gain_info); for (i = 0; (frame = id3_tag_findframe(tag, "TXXX", i)); i++) { if (frame->nfields < 3) @@ -341,15 +341,9 @@ parse_id3_replay_gain_info(struct id3_tag *tag) free(value); } - if (!found) { + return found || /* fall back on RVA2 if no replaygain tags found */ - found = parse_rva2(tag, replay_gain_info); - } - - if (found) - return replay_gain_info; - replay_gain_info_free(replay_gain_info); - return NULL; + parse_rva2(tag, replay_gain_info); } #endif @@ -408,11 +402,9 @@ static void mp3_parse_id3(struct mp3_data *data, size_t tagsize, } if (data->decoder != NULL) { - struct replay_gain_info *tmp_rgi = - parse_id3_replay_gain_info(id3_tag); - if (tmp_rgi != NULL) { - decoder_replay_gain(data->decoder, tmp_rgi); - replay_gain_info_free(tmp_rgi); + struct replay_gain_info rgi; + if (parse_id3_replay_gain_info(&rgi, id3_tag)) { + decoder_replay_gain(data->decoder, &rgi); data->found_replay_gain = true; } } @@ -879,15 +871,14 @@ mp3_decode_first_frame(struct mp3_data *data, struct tag **tag) if (data->decoder != NULL && !data->found_replay_gain && lame.track_gain) { - struct replay_gain_info *rgi - = replay_gain_info_new(); - rgi->tuples[REPLAY_GAIN_TRACK].gain = lame.track_gain; - rgi->tuples[REPLAY_GAIN_TRACK].peak = lame.peak; - decoder_replay_gain(data->decoder, rgi); - replay_gain_info_free(rgi); + struct replay_gain_info rgi; + replay_gain_info_init(&rgi); + rgi.tuples[REPLAY_GAIN_TRACK].gain = lame.track_gain; + rgi.tuples[REPLAY_GAIN_TRACK].peak = lame.peak; + decoder_replay_gain(data->decoder, &rgi); } } - } + } if (!data->max_frames) return false; -- cgit v1.2.3