summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Meerwald <p.meerwald@bct-electronic.com>2014-10-23 11:52:43 +0200
committerPeter Meerwald <pmeerw@pmeerw.net>2015-02-26 23:23:17 +0100
commit9f97f08f400a371e93ee6f178b5307427c79295c (patch)
tree05d71186f493c6288ca996adac873f22ab84de69
parentadb577c905f2e930bdd2bfe630d6ca0ea286d6cb (diff)
tagstruct: Use flist to potentially save calls to malloc()/free()
v2: (thanks David Henningson) * fix double assignment of data in pa_tagstruct_new_fixed(), two statements on one line Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
-rw-r--r--src/pulsecore/tagstruct.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
index 420650972..8a29957b4 100644
--- a/src/pulsecore/tagstruct.c
+++ b/src/pulsecore/tagstruct.c
@@ -35,6 +35,7 @@
#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
+#include <pulsecore/flist.h>
#include "tagstruct.h"
@@ -57,10 +58,13 @@ struct pa_tagstruct {
} per_type;
};
+PA_STATIC_FLIST_DECLARE(tagstructs, 0, pa_xfree);
+
pa_tagstruct *pa_tagstruct_new(void) {
pa_tagstruct*t;
- t = pa_xnew(pa_tagstruct, 1);
+ if (!(t = pa_flist_pop(PA_STATIC_FLIST_GET(tagstructs))))
+ t = pa_xnew(pa_tagstruct, 1);
t->data = t->per_type.appended;
t->allocated = MAX_APPENDED_SIZE;
t->length = t->rindex = 0;
@@ -74,7 +78,8 @@ pa_tagstruct *pa_tagstruct_new_fixed(const uint8_t* data, size_t length) {
pa_assert(data && length);
- t = pa_xnew(pa_tagstruct, 1);
+ if (!(t = pa_flist_pop(PA_STATIC_FLIST_GET(tagstructs))))
+ t = pa_xnew(pa_tagstruct, 1);
t->data = (uint8_t*) data;
t->allocated = t->length = length;
t->rindex = 0;
@@ -88,7 +93,8 @@ void pa_tagstruct_free(pa_tagstruct*t) {
if (t->type == PA_TAGSTRUCT_DYNAMIC)
pa_xfree(t->data);
- pa_xfree(t);
+ if (pa_flist_push(PA_STATIC_FLIST_GET(tagstructs), t) < 0)
+ pa_xfree(t);
}
static inline void extend(pa_tagstruct*t, size_t l) {