Ignore:
Timestamp:
Jan 29, 2011, 6:56:53 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) memory cache should use evbuffers to avoid unnecessary calls to memcpy -- done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/cache.c

    r11709 r11782  
    1111 */
    1212
     13#include <event2/buffer.h>
     14
    1315#include "transmission.h"
    1416#include "cache.h"
     
    4345    tr_block_index_t block;
    4446
    45     uint8_t * buf;
     47    struct evbuffer * evbuf;
    4648};
    4749
     
    171173    for( i=pos; i<pos+n; ++i ) {
    172174        b = blocks[i];
    173         memcpy( walk, b->buf, b->length );
     175        evbuffer_copyout( b->evbuf, walk, b->length );
    174176        walk += b->length;
    175         tr_free( b->buf );
     177        evbuffer_free( b->evbuf );
    176178        tr_free( b );
    177179    }
     
    320322                    uint32_t           offset,
    321323                    uint32_t           length,
    322                     const uint8_t    * writeme )
     324                    struct evbuffer  * writeme )
    323325{
    324326    struct cache_block * cb = findBlock( cache, torrent, piece, offset );
     
    332334        cb->length = length;
    333335        cb->block = _tr_block( torrent, piece, offset );
    334         cb->buf = NULL;
     336        cb->evbuf = evbuffer_new( );
    335337        tr_ptrArrayInsertSorted( &cache->blocks, cb, cache_block_compare );
    336338    }
     
    338340    cb->time = tr_time();
    339341
    340     tr_free( cb->buf );
    341     cb->buf = tr_memdup( writeme, cb->length );
     342    assert( cb->length == length );
     343    evbuffer_drain( cb->evbuf, evbuffer_get_length( cb->evbuf ) );
     344    evbuffer_remove_buffer( writeme, cb->evbuf, cb->length );
    342345
    343346    ++cache->cache_writes;
     
    359362
    360363    if( cb )
    361         memcpy( setme, cb->buf, len );
     364        evbuffer_copyout( cb->evbuf, setme, len );
    362365    else
    363366        err = tr_ioRead( torrent, piece, offset, len, setme );
Note: See TracChangeset for help on using the changeset viewer.