Changeset 7527


Ignore:
Timestamp:
Dec 29, 2008, 5:28:14 PM (12 years ago)
Author:
charles
Message:

(trunk libT) recycle the tr_list nodes when possible

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/list.c

    r7469 r7527  
    1515#include "utils.h"
    1616
     17/***
     18****
     19***/
     20
     21static tr_list * _unusedNodes = NULL;
     22
     23static const tr_list TR_LIST_INIT = { NULL, NULL, NULL };
     24
    1725static tr_list*
    1826node_alloc( void )
    1927{
    20     return tr_new0( tr_list, 1 );
     28    tr_list * node;
     29
     30    if( _unusedNodes == NULL )
     31        node = tr_new( tr_list, 1 );
     32    else {
     33        node = _unusedNodes;
     34        _unusedNodes = node->next;
     35    }
     36
     37    *node = TR_LIST_INIT;
     38    return node;
    2139}
    2240
     
    2442node_free( tr_list* node )
    2543{
    26     tr_free( node );
     44    if( node )
     45    {
     46        *node = TR_LIST_INIT;
     47        node->next = _unusedNodes;
     48        _unusedNodes = node;
     49    }
    2750}
    2851
Note: See TracChangeset for help on using the changeset viewer.