Ignore:
Timestamp:
Dec 29, 2008, 8:54:36 AM (12 years ago)
Author:
charles
Message:

(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_ptrArray, contain the tr_ptrArray directly rather than a pointer to one allocated elsewhere on the heap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r7476 r7524  
    18421842        char * tmp;
    18431843        tr_ptrArrayInsertSorted( dirtyFolders, tr_strdup( dir ), vstrcmp );
     1844
    18441845        tmp = tr_dirname( dir );
    18451846        tr_free( dir );
     
    18961897    char ** s;
    18971898    tr_file_index_t f;
    1898     tr_ptrArray * torrentFiles = tr_ptrArrayNew( );
    1899     tr_ptrArray * folders = tr_ptrArrayNew( );
    1900     tr_ptrArray * dirtyFolders = tr_ptrArrayNew( ); /* dirty == contains non-torrent files */
     1899    tr_ptrArray torrentFiles = TR_PTR_ARRAY_INIT;
     1900    tr_ptrArray folders      = TR_PTR_ARRAY_INIT;
     1901    tr_ptrArray dirtyFolders = TR_PTR_ARRAY_INIT; /* dirty == contains non-torrent files */
    19011902
    19021903    const char * firstFile = tor->info.files[0].name;
     
    19061907
    19071908    for( f=0; f<tor->info.fileCount; ++f )
    1908         tr_ptrArrayInsertSorted( torrentFiles, tor->info.files[f].name, vstrcmp );
     1909        tr_ptrArrayInsertSorted( &torrentFiles, tor->info.files[f].name, vstrcmp );
    19091910
    19101911    /* build the set of folders and dirtyFolders */
    1911     walkLocalData( tor, root, root, NULL, torrentFiles, folders, dirtyFolders );
     1912    walkLocalData( tor, root, root, NULL, &torrentFiles, &folders, &dirtyFolders );
    19121913
    19131914    /* close all the files because we're about to delete them */
     
    19191920
    19201921    /* try to remove entire folders first, so that the recycle bin will be tidy */
    1921     s = (char**) tr_ptrArrayPeek( folders, &n );
     1922    s = (char**) tr_ptrArrayPeek( &folders, &n );
    19221923    for( i=0; i<n; ++i )
    1923         if( tr_ptrArrayFindSorted( dirtyFolders, s[i], vstrcmp ) == NULL )
     1924        if( tr_ptrArrayFindSorted( &dirtyFolders, s[i], vstrcmp ) == NULL )
    19241925            fileFunc( s[i] );
    19251926
    1926     /* now blow away any remaining torrent files, such torrent files in dirty folders */
     1927    /* now blow away any remaining torrent files, such as torrent files in dirty folders */
    19271928    for( f=0; f<tor->info.fileCount; ++f ) {
    19281929        char * path = tr_buildPath( tor->downloadDir, tor->info.files[f].name, NULL );
     
    19351936     * won't prevent the upper folders from being deleted */
    19361937    {
    1937         tr_ptrArray * cleanFolders = tr_ptrArrayNew( );
    1938         s = (char**) tr_ptrArrayPeek( folders, &n );
     1938        tr_ptrArray cleanFolders = TR_PTR_ARRAY_INIT;
     1939        s = (char**) tr_ptrArrayPeek( &folders, &n );
    19391940        for( i=0; i<n; ++i )
    1940             if( tr_ptrArrayFindSorted( dirtyFolders, s[i], vstrcmp ) == NULL )
    1941                 tr_ptrArrayInsertSorted( cleanFolders, s[i], compareLongestFirst );
    1942         s = (char**) tr_ptrArrayPeek( cleanFolders, &n );
     1941            if( tr_ptrArrayFindSorted( &dirtyFolders, s[i], vstrcmp ) == NULL )
     1942                tr_ptrArrayInsertSorted( &cleanFolders, s[i], compareLongestFirst );
     1943        s = (char**) tr_ptrArrayPeek( &cleanFolders, &n );
    19431944        for( i=0; i<n; ++i )
    19441945            fileFunc( s[i] );
    1945         tr_ptrArrayFree( cleanFolders, NULL );
     1946        tr_ptrArrayDestruct( &cleanFolders, NULL );
    19461947    }
    19471948
    19481949    /* cleanup */
    1949     tr_ptrArrayFree( dirtyFolders, tr_free );
    1950     tr_ptrArrayFree( folders, tr_free );
    1951     tr_ptrArrayFree( torrentFiles, NULL );
     1950    tr_ptrArrayDestruct( &dirtyFolders, tr_free );
     1951    tr_ptrArrayDestruct( &folders, tr_free );
     1952    tr_ptrArrayDestruct( &torrentFiles, NULL );
    19521953    tr_free( root );
    19531954    tr_free( tmp );
     
    19631964        deleteLocalData( tor, fileFunc );
    19641965    else {
     1966        /* torrent only has one file */
    19651967        char * path = tr_buildPath( tor->downloadDir, tor->info.files[0].name, NULL );
     1968        tr_fdFileClose( path );
    19661969        fileFunc( path );
    19671970        tr_free( path );
Note: See TracChangeset for help on using the changeset viewer.