aboutsummaryrefslogtreecommitdiffstats
path: root/src/replay_gain_state.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-02-14 20:36:31 +0100
committerMax Kellermann <max@duempel.org>2010-02-17 07:22:44 +0100
commit5e0117b4441f257fcb1aab48b42a787567ebcbe6 (patch)
tree7233b273814def640145276f1a46d45b8cf274e4 /src/replay_gain_state.c
parentc05e6a1275621421eb0a7c3112b0401fa458841e (diff)
downloadmpd-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 '')
-rw-r--r--src/replay_gain_state.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/replay_gain_state.c b/src/replay_gain_state.c
index 4d494c62d..cfb2ce120 100644
--- a/src/replay_gain_state.c
+++ b/src/replay_gain_state.c
@@ -30,7 +30,7 @@ struct replay_gain_state {
enum replay_gain_mode mode;
- struct replay_gain_info *info;
+ struct replay_gain_info info;
float scale;
};
@@ -43,7 +43,7 @@ replay_gain_state_new(float preamp, float missing_preamp)
state->preamp = preamp;
state->scale = state->missing_preamp = missing_preamp;
state->mode = REPLAY_GAIN_OFF;
- state->info = NULL;
+ replay_gain_info_init(&state->info);
return state;
}
@@ -53,9 +53,6 @@ replay_gain_state_free(struct replay_gain_state *state)
{
assert(state != NULL);
- if (state->info != NULL)
- replay_gain_info_free(state->info);
-
g_free(state);
}
@@ -64,11 +61,11 @@ replay_gain_state_calc_scale(struct replay_gain_state *state)
{
assert(state != NULL);
- if (state->mode == REPLAY_GAIN_OFF || state->info == NULL)
+ if (state->mode == REPLAY_GAIN_OFF)
return;
const struct replay_gain_tuple *tuple =
- &state->info->tuples[state->mode];
+ &state->info.tuples[state->mode];
if (replay_gain_tuple_defined(tuple)) {
g_debug("computing ReplayGain scale with gain %f, peak %f",
tuple->gain, tuple->peak);
@@ -98,12 +95,10 @@ replay_gain_state_set_info(struct replay_gain_state *state,
{
assert(state != NULL);
- if (state->info != NULL)
- replay_gain_info_free(state->info);
-
- state->info = info != NULL
- ? replay_gain_info_dup(info)
- : NULL;
+ if (info != NULL)
+ state->info = *info;
+ else
+ replay_gain_info_init(&state->info);
replay_gain_state_calc_scale(state);
}