Ignore:
Timestamp:
Dec 30, 2008, 8:32:00 PM (13 years ago)
Author:
charles
Message:

(trunk libT) have a pool of reusable evbuffers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r7543 r7549  
    4545
    4646#include "transmission.h"
     47#include "list.h"
    4748#include "utils.h"
    4849#include "platform.h"
     
    240241        va_list           args;
    241242        char              timestr[64];
    242         struct evbuffer * buf = evbuffer_new( );
     243        struct evbuffer * buf = tr_getBuffer( );
    243244        char *            base = tr_basename( file );
    244245
     
    256257
    257258        tr_free( base );
    258         evbuffer_free( buf );
     259        tr_releaseBuffer( buf );
    259260    }
    260261}
     
    685686    va_list           ap;
    686687
    687     buf = evbuffer_new( );
     688    buf = tr_getBuffer( );
    688689    va_start( ap, fmt );
    689690
     
    692693
    693694    va_end( ap );
    694     evbuffer_free( buf );
     695    tr_releaseBuffer( buf );
    695696    return ret;
    696697}
     
    12941295    return (void*)(intptr_t)i;
    12951296}
     1297
     1298/***
     1299****
     1300***/
     1301
     1302static tr_list * _bufferList = NULL;
     1303
     1304struct evbuffer*
     1305tr_getBuffer( void )
     1306{
     1307    struct evbuffer * buf = tr_list_pop_front( &_bufferList );
     1308    if( buf == NULL )
     1309        buf = evbuffer_new( );
     1310    assert( !EVBUFFER_LENGTH( buf ) );
     1311    return buf;
     1312}
     1313
     1314void
     1315tr_releaseBuffer( struct evbuffer * buf )
     1316{
     1317    evbuffer_drain( buf, EVBUFFER_LENGTH( buf ) );
     1318    tr_list_prepend( &_bufferList, buf );
     1319}
Note: See TracChangeset for help on using the changeset viewer.