Ignore:
Timestamp:
Apr 4, 2011, 4:53:15 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) more heap pruning: avoid an unnecessary malloc() + free() when encrypting outbound messages

File:
1 edited

Legend:

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

    r12303 r12305  
    981981}
    982982
    983 static struct evbuffer_iovec *
    984 evbuffer_peek_all( struct evbuffer * buf, size_t * setme_vecCount )
    985 {
    986     const size_t byteCount = evbuffer_get_length( buf );
    987     const int vecCount = evbuffer_peek( buf, byteCount, NULL, NULL, 0 );
    988     struct evbuffer_iovec * iovec = tr_new0( struct evbuffer_iovec, vecCount );
    989     const int n = evbuffer_peek( buf, byteCount, NULL, iovec, vecCount );
    990     assert( n == vecCount );
    991     *setme_vecCount = n;
    992     return iovec;
    993 }
    994 
    995983static void
    996984maybeEncryptBuffer( tr_peerIo * io, struct evbuffer * buf )
     
    998986    if( io->encryption_type == PEER_ENCRYPTION_RC4 )
    999987    {
    1000         size_t i, n;
    1001         struct evbuffer_iovec * iovec = evbuffer_peek_all( buf, &n );
    1002 
    1003         for( i=0; i<n; ++i )
    1004             tr_cryptoEncrypt( io->crypto, iovec[i].iov_len, iovec[i].iov_base, iovec[i].iov_base );
    1005 
    1006         tr_free( iovec );
     988        struct evbuffer_ptr pos;
     989        struct evbuffer_iovec iovec;
     990        evbuffer_ptr_set( buf, &pos, 0, EVBUFFER_PTR_SET );
     991        do {
     992            evbuffer_peek( buf, -1, &pos, &iovec, 1 );
     993            tr_cryptoEncrypt( io->crypto, iovec.iov_len, iovec.iov_base, iovec.iov_base );
     994        } while( !evbuffer_ptr_set( buf, &pos, iovec.iov_len, EVBUFFER_PTR_ADD ) );
    1007995    }
    1008996}
Note: See TracChangeset for help on using the changeset viewer.