Changeset 7528


Ignore:
Timestamp:
Dec 29, 2008, 6:10:07 PM (12 years ago)
Author:
charles
Message:

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

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-msgs.c

    r7476 r7528  
    297297    tr_torrent *           torrent;
    298298
    299     tr_publisher_t *       publisher;
     299    tr_publisher           publisher;
    300300
    301301    struct evbuffer *      outMessages; /* all the non-piece messages */
     
    531531    assert( msgs->peer->msgs == msgs );
    532532
    533     tr_publisherPublish( msgs->publisher, msgs->peer, e );
     533    tr_publisherPublish( &msgs->publisher, msgs->peer, e );
    534534}
    535535
     
    22102210
    22112211    m = tr_new0( tr_peermsgs, 1 );
    2212     m->publisher = tr_publisherNew( );
     2212    m->publisher = TR_PUBLISHER_INIT;
    22132213    m->peer = peer;
    22142214    m->session = torrent->session;
     
    22302230    peer->msgs = m;
    22312231
    2232     *setme = tr_publisherSubscribe( m->publisher, func, userData );
     2232    *setme = tr_publisherSubscribe( &m->publisher, func, userData );
    22332233
    22342234    if( tr_peerIoSupportsLTEP( peer->io ) )
     
    22492249    {
    22502250        tr_timerFree( &msgs->pexTimer );
    2251         tr_publisherFree( &msgs->publisher );
     2251        tr_publisherDestruct( &msgs->publisher );
    22522252        reqListClear( &msgs->clientWillAskFor );
    22532253        reqListClear( &msgs->clientAskedFor );
     
    22682268                        tr_publisher_tag tag )
    22692269{
    2270     tr_publisherUnsubscribe( peer->publisher, tag );
    2271 }
    2272 
     2270    tr_publisherUnsubscribe( &peer->publisher, tag );
     2271}
     2272
  • trunk/libtransmission/publish.c

    r7404 r7528  
    2222};
    2323
    24 struct tr_publisher_s
    25 {
    26     tr_list *  list;
    27 };
    28 
    29 tr_publisher_t*
    30 tr_publisherNew( void )
    31 {
    32     return tr_new0( tr_publisher_t, 1 );
    33 }
     24const tr_publisher TR_PUBLISHER_INIT = { NULL };
    3425
    3526void
    36 tr_publisherFree( tr_publisher_t ** p )
     27tr_publisherDestruct( tr_publisher * p )
    3728{
    38     assert( p );
    39     assert( *p );
    40 
    41     tr_list_free( &( *p )->list, NULL );
    42     tr_free( *p );
    43     *p = NULL;
     29    tr_list_free( &p->list, NULL );
    4430}
    4531
    4632tr_publisher_tag
    47 tr_publisherSubscribe( tr_publisher_t * p,
    48                        tr_delivery_func func,
    49                        void *           user_data )
     33tr_publisherSubscribe( tr_publisher    * p,
     34                       tr_delivery_func   func,
     35                       void *             user_data )
    5036{
    5137    struct tr_publisher_node * node = tr_new( struct tr_publisher_node, 1 );
     
    5844
    5945void
    60 tr_publisherUnsubscribe( tr_publisher_t * p,
     46tr_publisherUnsubscribe( tr_publisher * p,
    6147                         tr_publisher_tag tag )
    6248{
     
    6652
    6753void
    68 tr_publisherPublish( tr_publisher_t * p,
     54tr_publisherPublish( tr_publisher * p,
    6955                     void *           source,
    7056                     void *           event )
  • trunk/libtransmission/publish.h

    r7404 r7528  
    1818#define _TR_PUBLISHER_H_
    1919
     20struct tr_list;
     21
    2022/**
    2123***  A lightweight implementation of the 'Observable' design pattern.
    2224**/
    2325
    24 typedef struct tr_publisher_s tr_publisher_t;
     26typedef struct tr_publisher
     27{
     28    struct tr_list * list;
     29}
     30tr_publisher;
    2531
    2632typedef void * tr_publisher_tag;
     
    3440**/
    3541
    36 tr_publisher_tag tr_publisherSubscribe( tr_publisher_t * publisher,
     42tr_publisher_tag tr_publisherSubscribe( tr_publisher  * publisher,
    3743                                        tr_delivery_func delivery_func,
    3844                                        void *           user_data );
    3945
    40 void             tr_publisherUnsubscribe( tr_publisher_t * publisher,
     46void             tr_publisherUnsubscribe( tr_publisher  * publisher,
    4147                                          tr_publisher_tag tag );
    4248
     
    4551**/
    4652
    47 tr_publisher_t * tr_publisherNew( void );
     53extern const tr_publisher TR_PUBLISHER_INIT;
    4854
    49 void             tr_publisherFree( tr_publisher_t ** publisher );
     55void             tr_publisherDestruct( tr_publisher * );
    5056
    51 void             tr_publisherPublish( tr_publisher_t * publisher,
     57void             tr_publisherPublish( tr_publisher * publisher,
    5258                                      void *           source,
    5359                                      void *           event );
  • trunk/libtransmission/tracker.c

    r7476 r7528  
    9393    tr_session *      session;
    9494
    95     tr_publisher_t *  publisher;
     95    tr_publisher      publisher;
    9696
    9797    /* torrent hash string */
     
    200200        event.messageType = type;
    201201        event.text = msg;
    202         tr_publisherPublish( t->publisher, t, &event );
     202        tr_publisherPublish( &t->publisher, t, &event );
    203203    }
    204204}
     
    239239    event.compactLen = compactLen;
    240240    if( compactLen )
    241         tr_publisherPublish( t->publisher, t, &event );
     241        tr_publisherPublish( &t->publisher, t, &event );
    242242}
    243243
     
    10491049
    10501050    t = tr_new0( tr_tracker, 1 );
    1051     t->publisher = tr_publisherNew( );
     1051    t->publisher                = TR_PUBLISHER_INIT;
    10521052    t->session                  = torrent->session;
    10531053    t->scrapeIntervalSec        = DEFAULT_SCRAPE_INTERVAL_SEC;
     
    10821082    tr_tracker * t = vt;
    10831083
    1084     tr_publisherFree( &t->publisher );
     1084    tr_publisherDestruct( &t->publisher );
    10851085    tr_free( t->name );
    10861086    tr_free( t->trackerID );
     
    11061106                     void *           user_data )
    11071107{
    1108     return tr_publisherSubscribe( t->publisher, func, user_data );
     1108    return tr_publisherSubscribe( &t->publisher, func, user_data );
    11091109}
    11101110
     
    11141114{
    11151115    if( t )
    1116         tr_publisherUnsubscribe( t->publisher, tag );
     1116        tr_publisherUnsubscribe( &t->publisher, tag );
    11171117}
    11181118
Note: See TracChangeset for help on using the changeset viewer.