Changeset 5031


Ignore:
Timestamp:
Feb 14, 2008, 12:52:58 AM (14 years ago)
Author:
charles
Message:

#706: reduce memory by 25% by cutting tr_file struct

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/metainfo.c

    r4404 r5031  
    306306    int i, j;
    307307
     308    for( i=0; i<inf->fileCount; ++i )
     309        tr_free( inf->files[i].name );
     310
    308311    tr_free( inf->pieces );
    309312    tr_free( inf->files );
     
    320323}
    321324
    322 static int getfile( char * buf, int size,
     325static int getfile( char ** setme,
    323326                    const char * prefix, benc_val_t * name )
    324327{
     
    326329    const char ** list;
    327330    int           ii, jj;
     331    char          buf[4096];
    328332
    329333    if( TYPE_LIST != name->type )
     
    365369    }
    366370
    367     strlcat_utf8( buf, prefix, size, 0 );
     371    memset( buf, 0, sizeof( buf ) );
     372    strlcat_utf8( buf, prefix, sizeof(buf), 0 );
    368373    for( ii = 0; jj > ii; ii++ )
    369374    {
    370         strlcat_utf8( buf, TR_PATH_DELIMITER_STR, size, 0 );
    371         strlcat_utf8( buf, list[ii], size, TR_PATH_DELIMITER );
     375        strlcat_utf8( buf, TR_PATH_DELIMITER_STR, sizeof(buf), 0 );
     376        strlcat_utf8( buf, list[ii], sizeof(buf), TR_PATH_DELIMITER );
    372377    }
    373378    free( list );
     379
     380    tr_free( *setme );
     381    *setme = tr_strdup( buf );
    374382
    375383    return TR_OK;
     
    640648        inf->files     = calloc( inf->fileCount, sizeof( inf->files[0] ) );
    641649
    642         if( NULL == inf->files )
    643         {
     650        if( !inf->files )
    644651            return TR_EINVALID;
    645         }
    646652
    647653        for( ii = 0; files->val.l.count > ii; ii++ )
     
    649655            item = &files->val.l.vals[ii];
    650656            path = tr_bencDictFindFirst( item, "path.utf-8", "path", NULL );
    651             if( getfile( inf->files[ii].name, sizeof( inf->files[0].name ),
    652                          inf->name, path ) )
     657            if( getfile( &inf->files[ii].name, inf->name, path ) )
    653658            {
    654659                tr_err( "%s \"path\" entry",
     
    669674    else if( NULL != length && TYPE_INT == length->type )
    670675    {
     676        char buf[4096];
     677
    671678        /* Single-file mode */
    672679        inf->isMultifile = 0;
     
    674681        inf->files     = calloc( 1, sizeof( inf->files[0] ) );
    675682
    676         if( NULL == inf->files )
    677         {
     683        if( !inf->files )
    678684            return TR_EINVALID;
    679         }
    680 
    681         strlcat_utf8( inf->files[0].name, name->val.s.s,
    682                       sizeof( inf->files[0].name ), TR_PATH_DELIMITER );
     685
     686        memset( buf, 0, sizeof( buf ) );
     687        strlcat_utf8( buf, name->val.s.s, sizeof(buf), TR_PATH_DELIMITER );
     688        tr_free( inf->files[0].name );
     689        inf->files[0].name = tr_strdup( buf );
    683690
    684691        inf->files[0].length = length->val.i;
  • trunk/libtransmission/transmission.h

    r5014 r5031  
    595595typedef struct tr_file
    596596{
    597     uint64_t length;                /* Length of the file, in bytes */
    598     char     name[MAX_PATH_LENGTH]; /* Path to the file */
    599     int8_t   priority;              /* TR_PRI_HIGH, _NORMAL, or _LOW */
    600     int8_t   dnd;                   /* nonzero if the file shouldn't be downloaded */
    601     int      firstPiece;            /* We need pieces [firstPiece... */
    602     int      lastPiece;             /* ...lastPiece] to dl this file */
    603     uint64_t offset;                /* file begins at the torrent's nth byte */
     597    uint64_t   length;      /* Length of the file, in bytes */
     598    char     * name;        /* Path to the file */
     599    int8_t     priority;    /* TR_PRI_HIGH, _NORMAL, or _LOW */
     600    int8_t     dnd;         /* nonzero if the file shouldn't be downloaded */
     601    int        firstPiece;  /* We need pieces [firstPiece... */
     602    int        lastPiece;   /* ...lastPiece] to dl this file */
     603    uint64_t   offset;      /* file begins at the torrent's nth byte */
    604604}
    605605tr_file;
Note: See TracChangeset for help on using the changeset viewer.