Changeset 12313


Ignore:
Timestamp:
Apr 5, 2011, 12:56:56 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) keep a pool of reusable tr_list nodes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/list.c

    r11709 r12313  
    1515#include "utils.h"
    1616
     17static const tr_list TR_LIST_CLEAR = { NULL, NULL, NULL };
     18
     19static tr_list * recycled_nodes = NULL;
     20
    1721static tr_list*
    1822node_alloc( void )
    1923{
    20     return tr_new0( tr_list, 1 );
     24    tr_list * ret;
     25
     26    if( recycled_nodes == NULL )
     27        ret = tr_new( tr_list, 1 );
     28    else {
     29        ret = recycled_nodes;
     30        recycled_nodes = recycled_nodes->next;
     31    }
     32
     33    *ret = TR_LIST_CLEAR;
     34    return ret;
    2135}
    2236
     
    2438node_free( tr_list* node )
    2539{
    26     tr_free( node );
     40    *node = TR_LIST_CLEAR;
     41    node->next = recycled_nodes;
     42    recycled_nodes = node;
    2743}
    2844
Note: See TracChangeset for help on using the changeset viewer.