Changeset 8688


Ignore:
Timestamp:
Jun 14, 2009, 2:23:43 PM (13 years ago)
Author:
charles
Message:

(trunk libT) avoid an extra malloc/free when deriving the scrape URL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/metainfo.c

    r8685 r8688  
    232232     * the scrape convention. If it does, substitute 'scrape' for
    233233     * 'announce' to find the scrape page.  */
    234     if( ( ( s =
    235                strrchr( announce, '/' ) ) ) && !strncmp( ++s, "announce", 8 ) )
    236     {
    237         struct evbuffer * buf = evbuffer_new( );
    238         evbuffer_add( buf, announce, s - announce );
    239         evbuffer_add( buf, "scrape", 6 );
    240         evbuffer_add_printf( buf, "%s", s + 8 );
    241         scrape = tr_strdup( EVBUFFER_DATA( buf ) );
    242         evbuffer_free( buf );
     234    if( ( ( s = strrchr( announce, '/' ) ) ) && !strncmp( ++s, "announce", 8 ) )
     235    {
     236        const char * prefix = announce;
     237        const size_t prefix_len = s - announce;
     238        const char * suffix = s + 8;
     239        const size_t suffix_len = strlen( suffix );
     240        const size_t alloc_len = prefix_len + 6 + suffix_len + 1;
     241        char * walk = scrape = tr_new( char, alloc_len );
     242        memcpy( walk, prefix, prefix_len ); walk += prefix_len;
     243        memcpy( walk, "scrape", 6 );        walk += 6;
     244        memcpy( walk, suffix, suffix_len ); walk += suffix_len;
     245        *walk++ = '\0';
     246        assert( walk - scrape == alloc_len );
    243247    }
    244248
Note: See TracChangeset for help on using the changeset viewer.