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

File:
1 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,
Note: See TracChangeset for help on using the changeset viewer.