mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
(trunk libT) keep a pool of reusable tr_list nodes
This commit is contained in:
parent
1e0f92ba78
commit
e0f6ade71e
1 changed files with 18 additions and 2 deletions
|
@ -14,16 +14,32 @@
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
static const tr_list TR_LIST_CLEAR = { NULL, NULL, NULL };
|
||||||
|
|
||||||
|
static tr_list * recycled_nodes = NULL;
|
||||||
|
|
||||||
static tr_list*
|
static tr_list*
|
||||||
node_alloc( void )
|
node_alloc( void )
|
||||||
{
|
{
|
||||||
return tr_new0( tr_list, 1 );
|
tr_list * ret;
|
||||||
|
|
||||||
|
if( recycled_nodes == NULL )
|
||||||
|
ret = tr_new( tr_list, 1 );
|
||||||
|
else {
|
||||||
|
ret = recycled_nodes;
|
||||||
|
recycled_nodes = recycled_nodes->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ret = TR_LIST_CLEAR;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
node_free( tr_list* node )
|
node_free( tr_list* node )
|
||||||
{
|
{
|
||||||
tr_free( node );
|
*node = TR_LIST_CLEAR;
|
||||||
|
node->next = recycled_nodes;
|
||||||
|
recycled_nodes = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
|
Loading…
Reference in a new issue