Changeset 7535


Ignore:
Timestamp:
Dec 30, 2008, 12:56:10 AM (12 years ago)
Author:
charles
Message:

(trunk libT) avoid a few more unnecessary malloc() + free() pairs

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-msgs.c

    r7528 r7535  
    3333#include "peer-mgr-private.h"
    3434#include "peer-msgs.h"
     35#include "platform.h" /* MAX_STACK_ARRAY_SIZE */
    3536#include "ratecontrol.h"
    3637#include "stats.h"
     
    14151416        const size_t nLeft = req->length - EVBUFFER_LENGTH( msgs->incoming.block );
    14161417        size_t n = MIN( nLeft, inlen );
    1417         uint8_t * buf = tr_new( uint8_t, n );
    1418         assert( EVBUFFER_LENGTH( inbuf ) >= n );
    1419         tr_peerIoReadBytes( msgs->peer->io, inbuf, buf, n );
    1420         evbuffer_add( msgs->incoming.block, buf, n );
     1418        size_t i = n;
     1419
     1420        while( i > 0 )
     1421        {
     1422            uint8_t buf[MAX_STACK_ARRAY_SIZE];
     1423            const size_t thisPass = MIN( n, sizeof( buf ) );
     1424            tr_peerIoReadBytes( msgs->peer->io, inbuf, buf, thisPass );
     1425            evbuffer_add( msgs->incoming.block, buf, thisPass );
     1426            i -= thisPass;
     1427        }
     1428
    14211429        fireClientGotData( msgs, n, TRUE );
    14221430        *setme_piece_bytes_read += n;
    1423         tr_free( buf );
    14241431        dbgmsg( msgs, "got %zu bytes for block %u:%u->%u ... %d remain",
    14251432               n, req->index, req->offset, req->length,
  • trunk/libtransmission/platform.h

    r7531 r7535  
    4040#endif
    4141
    42 #define MAX_STACK_ARRAY_SIZE 8192
     42#define MAX_STACK_ARRAY_SIZE 7168
    4343
    4444typedef struct tr_lock   tr_lock;
  • trunk/libtransmission/tracker.c

    r7533 r7535  
    729729    int                 reqtype; /* TR_REQ_* */
    730730    int                 torrentId;
    731     char *              url;
    732     tr_web_done_func * done_func;
     731    struct evbuffer   * url;
     732    tr_web_done_func  * done_func;
    733733    tr_session *        session;
    734734};
     
    737737freeRequest( struct tr_tracker_request * req )
    738738{
    739     tr_free( req->url );
     739    evbuffer_free( req->url );
    740740    tr_free( req );
    741741}
     
    807807    req->reqtype = reqtype;
    808808    req->done_func =  isStopping ? onStoppedResponse : onTrackerResponse;
    809     req->url = tr_strdup( EVBUFFER_DATA( url ) );
     809    req->url = url;
    810810    req->torrentId = tracker->torrentId;
    811811
    812     evbuffer_free( url );
    813812    return req;
    814813}
     
    829828    req->session = session;
    830829    req->reqtype = TR_REQ_SCRAPE;
    831     req->url = tr_strdup( EVBUFFER_DATA( url ) );
     830    req->url = url;
    832831    req->done_func = onScrapeResponse;
    833832    req->torrentId = tracker->torrentId;
    834833
    835     evbuffer_free( url );
    836834    return req;
    837835}
     
    899897    ++req->session->tracker->runningCount;
    900898
    901     tr_webRun( req->session, req->url, NULL,
     899    tr_webRun( req->session,
     900               (char*)EVBUFFER_DATA(req->url),
     901               NULL,
    902902               req->done_func, tr_int2ptr( req->torrentId ) );
    903903
Note: See TracChangeset for help on using the changeset viewer.