Changeset 8414


Ignore:
Timestamp:
May 16, 2009, 5:51:52 AM (12 years ago)
Author:
charles
Message:

(trunk) add an option to the JSON generator to disable the human-readable indentations. Keep indenting the data files such as settings.json, but don't indent the messages used for RPC. This cuts the cost of deflate()ing those RPC messages by about 80%...

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/daemon.c

    r8393 r8414  
    301301        struct evbuffer * buf = tr_getBuffer( );
    302302
    303         tr_bencSaveAsJSON( &settings, buf );
     303        tr_bencSaveAsJSON( &settings, buf, TRUE );
    304304        fprintf( stderr, "%s", (char*)EVBUFFER_DATA(buf) );
    305305
  • trunk/daemon/remote.c

    r8389 r8414  
    619619        {
    620620            struct evbuffer * buf = tr_getBuffer( );
    621             reqs[reqCount++] = tr_strdup( tr_bencSaveAsJSON( &top, buf ) );
     621            reqs[reqCount++] = tr_strdup( tr_bencSaveAsJSON( &top, buf, FALSE ) );
    622622            tr_releaseBuffer( buf );
    623623        }
     
    12621262
    12631263    if( debug )
    1264         fprintf( stderr, "got response:\n--------\n%*.*s\n--------\n",
    1265                  (int)len, (int)len, (const char*) response );
     1264        fprintf( stderr, "got response (len %d):\n--------\n%*.*s\n--------\n",
     1265                 (int)len, (int)len, (int)len, (const char*) response );
    12661266
    12671267    if( tr_jsonParse( response, len, &top, NULL ) )
  • trunk/gtk/tr-core.c

    r8404 r8414  
    14451445tr_core_exec( TrCore * core, const tr_benc * top )
    14461446{
    1447     char * json = tr_bencToJSON( top );
     1447    char * json = tr_bencToJSON( top, FALSE );
    14481448    tr_core_exec_json( core, json );
    14491449    tr_free( json );
  • trunk/libtransmission/bencode-test.c

    r8158 r8414  
    325325
    326326    tr_bencLoad( benc_str, strlen( benc_str ), &top, NULL );
    327     serialized = tr_bencSaveAsJSON( &top, buf );
     327    serialized = tr_bencSaveAsJSON( &top, buf, TRUE );
    328328    stripWhitespace( serialized );
    329329#if 0
  • trunk/libtransmission/bencode.c

    r8372 r8414  
    11811181struct jsonWalk
    11821182{
    1183     tr_list *          parents;
     1183    tr_bool doIndent;
     1184    tr_list * parents;
    11841185    struct evbuffer *  out;
    11851186};
     
    11881189jsonIndent( struct jsonWalk * data )
    11891190{
    1190     char buf[1024];
    1191     const int width = tr_list_size( data->parents ) * 4;
    1192 
    1193     buf[0] = '\n';
    1194     memset( buf+1, ' ', width );
    1195     evbuffer_add( data->out, buf, 1+width );
     1191    if( data->doIndent )
     1192    {
     1193        char buf[1024];
     1194        const int width = tr_list_size( data->parents ) * 4;
     1195
     1196        buf[0] = '\n';
     1197        memset( buf+1, ' ', width );
     1198        evbuffer_add( data->out, buf, 1+width );
     1199    }
    11961200}
    11971201
     
    13971401                                           
    13981402char*
    1399 tr_bencSaveAsJSON( const tr_benc * top, struct evbuffer * out )
     1403tr_bencSaveAsJSON( const tr_benc * top, struct evbuffer * out, tr_bool doIndent )
    14001404{
    14011405    struct jsonWalk data;
     
    14031407    evbuffer_drain( out, EVBUFFER_LENGTH( out ) );
    14041408
     1409    data.doIndent = doIndent;
    14051410    data.out = out;
    14061411    data.parents = NULL;
     
    14151420
    14161421char*
    1417 tr_bencToJSON( const tr_benc * top )
     1422tr_bencToJSON( const tr_benc * top, tr_bool doIndent )
    14181423{
    14191424    char * ret;
    14201425    struct evbuffer * buf = evbuffer_new( );
    1421     tr_bencSaveAsJSON( top, buf );
     1426    tr_bencSaveAsJSON( top, buf, doIndent );
    14221427    ret = tr_strndup( EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) );
    14231428    evbuffer_free( buf );
     
    15621567{
    15631568    struct evbuffer * buf = tr_getBuffer( );
    1564     const char * json = tr_bencSaveAsJSON( b, buf );
     1569    const char * json = tr_bencSaveAsJSON( b, buf, TRUE );
    15651570    const int err = saveFile( filename, json, EVBUFFER_LENGTH( buf ) );
    15661571    tr_releaseBuffer( buf );
  • trunk/libtransmission/bencode.h

    r8268 r8414  
    8585char*     tr_bencSave( const tr_benc * val, int * len );
    8686
    87 char*     tr_bencSaveAsJSON( const tr_benc * top, struct evbuffer * out );
    88 
    89 char*     tr_bencToJSON( const tr_benc * top );
     87char*     tr_bencSaveAsJSON( const tr_benc * top, struct evbuffer * out, tr_bool doIndent );
     88
     89char*     tr_bencToJSON( const tr_benc * top, tr_bool doIndent );
    9090
    9191int       tr_bencSaveFile( const char * filename, const tr_benc * );
  • trunk/libtransmission/json-test.c

    r8158 r8414  
    7575    check( tr_bencDictFindStr( &top, "key", &str ) );
    7676    check( !strcmp( str, "Letöltések" ) );
    77     json = tr_bencSaveAsJSON( &top, buf );
     77    json = tr_bencSaveAsJSON( &top, buf, TRUE );
    7878    if( !err )
    7979        tr_bencFree( &top );
  • trunk/libtransmission/rpc-server.c

    r8400 r8414  
    270270                tr_bencDictAddStr( args, "metainfo", b64 );
    271271                tr_bencDictAddBool( args, "paused", paused );
    272                 tr_bencSaveAsJSON( &top, json );
     272                tr_bencSaveAsJSON( &top, json, FALSE );
    273273                tr_rpc_request_exec_json( server->session,
    274274                                          EVBUFFER_DATA( json ),
  • trunk/libtransmission/rpcimpl.c

    r8412 r8414  
    9393    tr_bencDictAddStr( data->response, "result", result );
    9494
    95     tr_bencSaveAsJSON( data->response, buf );
     95    tr_bencSaveAsJSON( data->response, buf, FALSE );
    9696    (*data->callback)( data->session, (const char*)EVBUFFER_DATA(buf),
    9797                       EVBUFFER_LENGTH(buf), data->callback_user_data );
     
    13371337        if( tr_bencDictFindInt( request, "tag", &tag ) )
    13381338            tr_bencDictAddInt( &response, "tag", tag );
    1339         tr_bencSaveAsJSON( &response, buf );
     1339        tr_bencSaveAsJSON( &response, buf, FALSE );
    13401340        (*callback)( session, (const char*)EVBUFFER_DATA(buf),
    13411341                     EVBUFFER_LENGTH( buf ), callback_user_data );
     
    13591359        if( tr_bencDictFindInt( request, "tag", &tag ) )
    13601360            tr_bencDictAddInt( &response, "tag", tag );
    1361         tr_bencSaveAsJSON( &response, buf );
     1361        tr_bencSaveAsJSON( &response, buf, FALSE );
    13621362        (*callback)( session, (const char*)EVBUFFER_DATA(buf),
    13631363                     EVBUFFER_LENGTH(buf), callback_user_data );
  • trunk/libtransmission/torrent.c

    r8413 r8414  
    10651065        else
    10661066        {
    1067             const tr_block_index_t firstBlockOfLastPiece = tr_torPieceFirstBlock( tor, f->lastPiece );
    1068             const tr_block_index_t lastBlockOfFirstPiece = tr_torPieceFirstBlock( tor, f->firstPiece )
    1069                                                          + tr_torPieceCountBlocks( tor, f->firstPiece )
    1070                                                          - 1;
     1067            int64_t b = 0;
     1068            const tr_block_index_t firstBlockOfLastPiece
     1069                       = tr_torPieceFirstBlock( tor, f->lastPiece );
     1070            const tr_block_index_t lastBlockOfFirstPiece
     1071                       = tr_torPieceFirstBlock( tor, f->firstPiece )
     1072                         + tr_torPieceCountBlocks( tor, f->firstPiece ) - 1;
     1073
    10711074            /* the rest of the first piece */
    10721075            for( i=firstBlock+1; i<lastBlock && i<=lastBlockOfFirstPiece; ++i )
    10731076                if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
    1074                     total += tor->blockSize;
     1077                    ++b;
    10751078
    10761079            /* the middle pieces */
    1077             if( f->firstPiece + 1 < f->lastPiece ) {
    1078                 uint64_t b = tor->blockCountInPiece * ( f->lastPiece - ( f->firstPiece + 1 ) );
     1080            if( f->firstPiece + 1 < f->lastPiece )
    10791081                for( i=f->firstPiece+1; i<f->lastPiece; ++i )
    1080                     b -= tr_cpMissingBlocksInPiece( &tor->completion, i );
    1081                 b *= tor->blockSize;
    1082                 total += b;
    1083             }
     1082                    b += tor->blockCountInPiece - tr_cpMissingBlocksInPiece( &tor->completion, i );
    10841083
    10851084            /* the rest of the last piece */
    10861085            for( i=firstBlockOfLastPiece; i<lastBlock; ++i )
    10871086                if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
    1088                     total += tor->blockSize;
     1087                    ++b;
     1088
     1089            b *= tor->blockSize;
     1090            total += b;
    10891091        }
    10901092
  • trunk/qt/prefs.cc

    r8401 r8414  
    218218
    219219    /* write back out the serialized preferences */
    220     char * json = tr_bencToJSON( &top );
     220    char * json = tr_bencToJSON( &top, TRUE );
    221221    if( json && *json ) {
    222222        file.open( QIODevice::WriteOnly | QIODevice::Text );
  • trunk/qt/session.cc

    r8405 r8414  
    532532Session :: exec( const tr_benc * request )
    533533{
    534     char * str( tr_bencToJSON( request ) );
     534    char * str( tr_bencToJSON( request, FALSE ) );
    535535    exec( str );
    536536    tr_free( str );
Note: See TracChangeset for help on using the changeset viewer.