Changeset 10909


Ignore:
Timestamp:
Jun 30, 2010, 6:03:55 AM (11 years ago)
Author:
charles
Message:

(trunk) avoid a few unnecessary type conversions. remove a few unnecessary mutex locks.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/history.c

    r10332 r10909  
    1717struct history_slice
    1818{
    19     double n;
     19    unsigned int n;
    2020    uint64_t date;
    2121};
     
    2525    int newest;
    2626    int sliceCount;
    27     int precision_msec;
     27    unsigned int precision_msec;
    2828    struct history_slice * slices;
    2929};
    3030
    3131void
    32 tr_historyAdd( tr_recentHistory * h, uint64_t now, double n )
     32tr_historyAdd( tr_recentHistory * h, uint64_t now, unsigned int n )
    3333{
    3434    if( h->slices[h->newest].date + h->precision_msec >= now )
     
    4141}
    4242
    43 double
    44 tr_historyGet( const tr_recentHistory * h, uint64_t now, int msec )
     43unsigned int
     44tr_historyGet( const tr_recentHistory * h, uint64_t now, unsigned int msec )
    4545{
    46     double n = 0;
     46    unsigned int n = 0;
    4747    const uint64_t cutoff = (now?now:tr_date()) - msec;
    4848    int i = h->newest;
     
    6363
    6464tr_recentHistory *
    65 tr_historyNew( int seconds, int bins_per_second )
     65tr_historyNew( unsigned int seconds, unsigned int bins_per_second )
    6666{
    6767    tr_recentHistory * h;
     
    6969    h = tr_new0( tr_recentHistory, 1 );
    7070    h->precision_msec = 1000 / bins_per_second;
    71     h->sliceCount = seconds * bins_per_second;
     71    h->sliceCount = (int)(seconds * bins_per_second);
    7272    h->slices = tr_new0( struct history_slice, h->sliceCount );
    7373
  • trunk/libtransmission/history.h

    r10332 r10909  
    3333 *        For a precision of 1/20th of a second, use a precision of 20.
    3434 */
    35 tr_recentHistory * tr_historyNew( int seconds, int precision );
     35tr_recentHistory * tr_historyNew( unsigned int seconds, unsigned int precision );
    3636
    3737/** @brief destroy an existing tr_recentHistory object. */
     
    4343 * @param n how many items to add to the history's counter
    4444 */
    45 void tr_historyAdd( tr_recentHistory *, uint64_t when, double n );
     45void tr_historyAdd( tr_recentHistory *, uint64_t when, unsigned int n );
    4646
    4747/**
     
    5050 * @param seconds how many seconds to count back through.
    5151 */
    52 double tr_historyGet( const tr_recentHistory *, uint64_t when, int seconds );
     52unsigned int tr_historyGet( const tr_recentHistory *, uint64_t when, unsigned int seconds );
    5353
    5454#endif
  • trunk/libtransmission/utils.c

    r10844 r10909  
    123123tr_getMessageLevel( void )
    124124{
    125     int ret;
    126     tr_lockLock( messageLock );
    127 
    128     ret = messageLevel;
    129 
    130     tr_lockUnlock( messageLock );
    131     return ret;
     125    return messageLevel;
    132126}
    133127
     
    135129tr_setMessageQueuing( tr_bool enabled )
    136130{
    137     tr_lockLock( messageLock );
    138 
    139131    messageQueuing = enabled;
    140 
    141     tr_lockUnlock( messageLock );
    142132}
    143133
     
    145135tr_getMessageQueuing( void )
    146136{
    147     int ret;
    148     tr_lockLock( messageLock );
    149 
    150     ret = messageQueuing;
    151 
    152     tr_lockUnlock( messageLock );
    153     return ret;
     137    return messageQueuing != 0;
    154138}
    155139
  • trunk/libtransmission/utils.h

    r10844 r10909  
    323323 * @return a newly-allocated copy of `src' that can be freed with tr_free()
    324324 */
    325 static inline void* tr_memdup( const void * src, int byteCount )
     325static inline void* tr_memdup( const void * src, size_t byteCount )
    326326{
    327327    return memcpy( tr_malloc( byteCount ), src, byteCount );
     
    354354static inline char* tr_strdup( const void * in )
    355355{
    356     return tr_strndup( in, in ? strlen( (const char *) in ) : 0 );
     356    return tr_strndup( in, in ? (int)strlen((const char *)in) : 0 );
    357357}
    358358
     
    522522
    523523/** @brief convenience function to remove an item from an array */
    524 static inline void tr_removeElementFromArray( void   * array,
    525                                               int      index_to_remove,
    526                                               size_t   sizeof_element,
    527                                               size_t   nmemb )
     524static inline void tr_removeElementFromArray( void         * array,
     525                                              unsigned int   index_to_remove,
     526                                              size_t         sizeof_element,
     527                                              size_t         nmemb )
    528528{
    529529    char * a = (char*) array;
Note: See TracChangeset for help on using the changeset viewer.