mirror of
https://github.com/transmission/transmission
synced 2025-02-03 13:03:50 +00:00
(trunk libT) recycle the tr_list nodes when possible
This commit is contained in:
parent
e7ffb4da03
commit
3a01d2e619
1 changed files with 25 additions and 2 deletions
|
@ -14,16 +14,39 @@
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
/***
|
||||||
|
****
|
||||||
|
***/
|
||||||
|
|
||||||
|
static tr_list * _unusedNodes = NULL;
|
||||||
|
|
||||||
|
static const tr_list TR_LIST_INIT = { NULL, NULL, NULL };
|
||||||
|
|
||||||
static tr_list*
|
static tr_list*
|
||||||
node_alloc( void )
|
node_alloc( void )
|
||||||
{
|
{
|
||||||
return tr_new0( tr_list, 1 );
|
tr_list * node;
|
||||||
|
|
||||||
|
if( _unusedNodes == NULL )
|
||||||
|
node = tr_new( tr_list, 1 );
|
||||||
|
else {
|
||||||
|
node = _unusedNodes;
|
||||||
|
_unusedNodes = node->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
*node = TR_LIST_INIT;
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
node_free( tr_list* node )
|
node_free( tr_list* node )
|
||||||
{
|
{
|
||||||
tr_free( node );
|
if( node )
|
||||||
|
{
|
||||||
|
*node = TR_LIST_INIT;
|
||||||
|
node->next = _unusedNodes;
|
||||||
|
_unusedNodes = node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
|
Loading…
Reference in a new issue