Changeset 7531


Ignore:
Timestamp:
Dec 29, 2008, 7:01:47 PM (12 years ago)
Author:
charles
Message:

(trunk libT) omit unnecessary malloc/free calls in peer-io

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r7404 r7531  
    230230    while( bytesLeft )
    231231    {
    232         uint8_t   buf[8192];
     232        uint8_t buf[MAX_STACK_ARRAY_SIZE];
    233233        const int len = MIN( bytesLeft, sizeof( buf ) );
    234234        success = !tr_ioRead( tor, pieceIndex, offset, len, buf );
  • trunk/libtransmission/peer-io.c

    r7486 r7531  
    3232#include "net.h"
    3333#include "peer-io.h"
     34#include "platform.h" /* MAX_STACK_ARRAY_SIZE */
    3435#include "trevent.h"
    3536#include "utils.h"
     
    770771                     size_t            byteCount )
    771772{
    772     uint8_t * tmp;
     773    uint8_t tmp[MAX_STACK_ARRAY_SIZE];
    773774
    774775    switch( io->encryptionMode )
     
    779780
    780781        case PEER_ENCRYPTION_RC4:
    781             tmp = tr_new( uint8_t, byteCount );
    782             tr_cryptoEncrypt( io->crypto, byteCount, bytes, tmp );
    783             evbuffer_add( outbuf, tmp, byteCount );
    784             tr_free( tmp );
     782            evbuffer_expand( outbuf, byteCount );
     783            while( byteCount > 0 ) {
     784                const size_t thisPass = MIN( byteCount, sizeof( tmp ) );
     785                tr_cryptoEncrypt( io->crypto, thisPass, bytes, tmp );
     786                evbuffer_add( outbuf, tmp, thisPass );
     787                bytes += thisPass;
     788                byteCount -= thisPass;
     789            }
    785790            break;
    786791
     
    885890                size_t            byteCount )
    886891{
    887     uint8_t * tmp;
    888 
    889     assert( tr_isPeerIo( io ) );
    890 
    891     tmp = tr_new( uint8_t, byteCount );
    892     tr_peerIoReadBytes( io, inbuf, tmp, byteCount );
    893     tr_free( tmp );
     892    uint8_t tmp[MAX_STACK_ARRAY_SIZE];
     893
     894    assert( tr_isPeerIo( io ) );
     895
     896    while( byteCount > 0 )
     897    {
     898        const size_t thisPass = MIN( byteCount, sizeof( tmp ) );
     899        tr_peerIoReadBytes( io, inbuf, tmp, thisPass );
     900        byteCount -= thisPass;
     901    }
    894902}
    895903
  • trunk/libtransmission/platform.h

    r7385 r7531  
    3939 #define MAX_PATH_LENGTH  1024
    4040#endif
     41
     42#define MAX_STACK_ARRAY_SIZE 8192
    4143
    4244typedef struct tr_lock   tr_lock;
Note: See TracChangeset for help on using the changeset viewer.