Changeset 12390


Ignore:
Timestamp:
Apr 27, 2011, 8:52:07 PM (10 years ago)
Author:
jordan
Message:

(trunk libT) heap pruning: using the same mechanism as in r12388, avoid an unnecessary malloc+memcpy+free when building the URL for a webseed download request

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/webseed.c

    r12280 r12390  
    245245}
    246246
    247 static char*
     247static struct evbuffer *
    248248make_url( tr_webseed * w, const tr_file * file )
    249249{
    250     struct evbuffer * out = evbuffer_new( );
    251 
    252     evbuffer_add( out, w->base_url, w->base_url_len );
     250    struct evbuffer * buf = evbuffer_new( );
     251
     252    evbuffer_add( buf, w->base_url, w->base_url_len );
    253253
    254254    /* if url ends with a '/', add the torrent name */
    255255    if( w->base_url[w->base_url_len - 1] == '/' && file->name )
    256         tr_http_escape( out, file->name, strlen(file->name), false );
    257 
    258     return evbuffer_free_to_str( out );
     256        tr_http_escape( buf, file->name, strlen(file->name), false );
     257
     258    return buf;
    259259}
    260260
     
    265265    if( tor != NULL )
    266266    {
    267         char * url;
    268267        char range[64];
     268        struct evbuffer * url;
    269269
    270270        const tr_info * inf = tr_torrentInfo( tor );
     
    291291        tr_snprintf( range, sizeof range, "%"PRIu64"-%"PRIu64,
    292292                     file_offset, file_offset + this_pass - 1 );
    293         tr_webRunWithBuffer( t->session, url, range, NULL,
    294                              web_response_func, t, t->content );
    295         tr_free( url );
     293        tr_webRunWithBuffer( t->session, (char *) evbuffer_pullup( url, -1 ),
     294                             range, NULL, web_response_func, t, t->content );
     295        evbuffer_free( url );
    296296    }
    297297}
Note: See TracChangeset for help on using the changeset viewer.