mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									adb577c905
								
							
						
					
					
						commit
						9f97f08f40
					
				
					 1 changed files with 9 additions and 3 deletions
				
			
		| 
						 | 
					@ -35,6 +35,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <pulsecore/socket.h>
 | 
					#include <pulsecore/socket.h>
 | 
				
			||||||
#include <pulsecore/macro.h>
 | 
					#include <pulsecore/macro.h>
 | 
				
			||||||
 | 
					#include <pulsecore/flist.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "tagstruct.h"
 | 
					#include "tagstruct.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,9 +58,12 @@ struct pa_tagstruct {
 | 
				
			||||||
    } per_type;
 | 
					    } per_type;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PA_STATIC_FLIST_DECLARE(tagstructs, 0, pa_xfree);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pa_tagstruct *pa_tagstruct_new(void) {
 | 
					pa_tagstruct *pa_tagstruct_new(void) {
 | 
				
			||||||
    pa_tagstruct*t;
 | 
					    pa_tagstruct*t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(t = pa_flist_pop(PA_STATIC_FLIST_GET(tagstructs))))
 | 
				
			||||||
        t = pa_xnew(pa_tagstruct, 1);
 | 
					        t = pa_xnew(pa_tagstruct, 1);
 | 
				
			||||||
    t->data = t->per_type.appended;
 | 
					    t->data = t->per_type.appended;
 | 
				
			||||||
    t->allocated = MAX_APPENDED_SIZE;
 | 
					    t->allocated = MAX_APPENDED_SIZE;
 | 
				
			||||||
| 
						 | 
					@ -74,6 +78,7 @@ pa_tagstruct *pa_tagstruct_new_fixed(const uint8_t* data, size_t length) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(data && length);
 | 
					    pa_assert(data && length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(t = pa_flist_pop(PA_STATIC_FLIST_GET(tagstructs))))
 | 
				
			||||||
        t = pa_xnew(pa_tagstruct, 1);
 | 
					        t = pa_xnew(pa_tagstruct, 1);
 | 
				
			||||||
    t->data = (uint8_t*) data;
 | 
					    t->data = (uint8_t*) data;
 | 
				
			||||||
    t->allocated = t->length = length;
 | 
					    t->allocated = t->length = length;
 | 
				
			||||||
| 
						 | 
					@ -88,6 +93,7 @@ void pa_tagstruct_free(pa_tagstruct*t) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (t->type == PA_TAGSTRUCT_DYNAMIC)
 | 
					    if (t->type == PA_TAGSTRUCT_DYNAMIC)
 | 
				
			||||||
        pa_xfree(t->data);
 | 
					        pa_xfree(t->data);
 | 
				
			||||||
 | 
					    if (pa_flist_push(PA_STATIC_FLIST_GET(tagstructs), t) < 0)
 | 
				
			||||||
        pa_xfree(t);
 | 
					        pa_xfree(t);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue