Changeset 588


Ignore:
Timestamp:
Jul 6, 2006 2:27:31 PM (18 years ago)
Author:
bennylp
Message:

Improve the search for correct size in caching pool

Location:
pjproject/trunk/pjlib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/pool.h

    r364 r588  
    157157    /** Pool factory. */ 
    158158    pj_pool_factory *factory; 
     159 
     160    /** Data put by factory */ 
     161    void            *factory_data; 
    159162 
    160163    /** Current capacity allocated by the pool. */ 
  • pjproject/trunk/pjlib/src/pj/pool_caching.c

    r582 r588  
    3939}; 
    4040 
     41/* Index where the search for size should begin. 
     42 * Start with pool_sizes[5], which is 8192. 
     43 */ 
     44#define START_SIZE  5 
     45 
    4146 
    4247PJ_DEF(void) pj_caching_pool_init( pj_caching_pool *cp,  
     
    119124     * for this purpose. 
    120125     */ 
    121     for (idx=0;  
    122          idx < PJ_CACHING_POOL_ARRAY_SIZE && pool_sizes[idx] < initial_size;  
    123          ++idx) 
    124         ; 
     126    if (initial_size <= pool_sizes[START_SIZE]) { 
     127        for (idx=START_SIZE-1;  
     128             idx >= 0 && pool_sizes[idx] >= initial_size; 
     129             --idx) 
     130            ; 
     131        ++idx; 
     132    } else { 
     133        for (idx=START_SIZE+1;  
     134             idx < PJ_CACHING_POOL_ARRAY_SIZE &&  
     135                  pool_sizes[idx] < initial_size; 
     136             ++idx) 
     137            ; 
     138    } 
    125139 
    126140    /* Check whether there's a pool in the list. */ 
     
    156170    pj_list_insert_before( &cp->used_list, pool ); 
    157171 
     172    /* Mark factory data */ 
     173    pool->factory_data = (void*) idx; 
     174 
    158175    /* Increment used count. */ 
    159176    ++cp->used_count; 
     
    167184    pj_caching_pool *cp = (pj_caching_pool*)pf; 
    168185    unsigned pool_capacity; 
    169     int i; 
     186    unsigned i; 
    170187 
    171188    PJ_CHECK_STACK(); 
     
    204221     * Otherwise put the pool in our recycle list. 
    205222     */ 
    206     for (i=0; i < PJ_CACHING_POOL_ARRAY_SIZE && pool_sizes[i] != pool_capacity; ++i) 
    207         ; 
    208  
    209     pj_assert( i != PJ_CACHING_POOL_ARRAY_SIZE ); 
    210     if (i == PJ_CACHING_POOL_ARRAY_SIZE) { 
     223    i = (unsigned)pool->factory_data; 
     224 
     225    pj_assert(i<PJ_CACHING_POOL_ARRAY_SIZE); 
     226    if (i >= PJ_CACHING_POOL_ARRAY_SIZE ) { 
    211227        /* Something has gone wrong with the pool. */ 
    212228        pj_pool_destroy_int(pool); 
Note: See TracChangeset for help on using the changeset viewer.