diff options
author | Max Kellermann <max@duempel.org> | 2010-02-14 20:36:31 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-02-17 07:22:44 +0100 |
commit | 5e0117b4441f257fcb1aab48b42a787567ebcbe6 (patch) | |
tree | 7233b273814def640145276f1a46d45b8cf274e4 /src/decoder/vorbis_decoder_plugin.c | |
parent | c05e6a1275621421eb0a7c3112b0401fa458841e (diff) | |
download | mpd-5e0117b4441f257fcb1aab48b42a787567ebcbe6.tar.gz mpd-5e0117b4441f257fcb1aab48b42a787567ebcbe6.tar.xz mpd-5e0117b4441f257fcb1aab48b42a787567ebcbe6.zip |
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.
Diffstat (limited to 'src/decoder/vorbis_decoder_plugin.c')
-rw-r--r-- | src/decoder/vorbis_decoder_plugin.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/decoder/vorbis_decoder_plugin.c b/src/decoder/vorbis_decoder_plugin.c index 0163ca9ff..25e91c142 100644 --- a/src/decoder/vorbis_decoder_plugin.c +++ b/src/decoder/vorbis_decoder_plugin.c @@ -134,14 +134,13 @@ vorbis_comment_value(const char *comment, const char *needle) return NULL; } -static struct replay_gain_info * -vorbis_comments_to_replay_gain(char **comments) +static bool +vorbis_comments_to_replay_gain(struct replay_gain_info *rgi, char **comments) { - struct replay_gain_info *rgi; const char *temp; bool found = false; - rgi = replay_gain_info_new(); + replay_gain_info_init(rgi); while (*comments) { if ((temp = @@ -165,12 +164,7 @@ vorbis_comments_to_replay_gain(char **comments) comments++; } - if (!found) { - replay_gain_info_free(rgi); - rgi = NULL; - } - - return rgi; + return found; } static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber"; @@ -334,7 +328,6 @@ vorbis_stream_decode(struct decoder *decoder, if (current_section != prev_section) { char **comments; - struct replay_gain_info *new_rgi; vi = ov_info(&vf, -1); if (vi == NULL) { @@ -352,11 +345,10 @@ vorbis_stream_decode(struct decoder *decoder, comments = ov_comment(&vf, -1)->user_comments; vorbis_send_comments(decoder, input_stream, comments); - new_rgi = vorbis_comments_to_replay_gain(comments); - if (new_rgi != NULL) { - decoder_replay_gain(decoder, new_rgi); - replay_gain_info_free(new_rgi); - } + + struct replay_gain_info rgi; + if (vorbis_comments_to_replay_gain(&rgi, comments)) + decoder_replay_gain(decoder, &rgi); prev_section = current_section; } |