Changeset 454 for branches

Show
Ignore:
Timestamp:
08/27/07 21:01:11 (15 months ago)
Author:
krobillard
Message:

Optimized ur_internDefault(). Repeated calls to _orderWords() were causing a
massive performance hit.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/thune/thread_safe/context.c

    r431 r454  
    303303 
    304304/** 
    305   Add word to context if it does not already exist. 
    306   If added, the word is initialied as unset. 
    307  
    308   \return  Index of word in context. 
    309 */ 
    310 int ur_internWordT( UThread* ut, const UContext* ctx, UAtom atom ) 
    311 { 
    312     int wrdN; 
    313     UBlock* vblk; 
     305  Find word in context by atom. 
     306  \return  Word index or -1 if not found. 
     307*/ 
     308static int _lookupNoSort( UThread* ut, const UContext* ctx, UAtom atom ) 
     309{ 
    314310    UBlock* wblk; 
    315311    UCell* it; 
    316312    UCell* end; 
    317  
    318  
    319     // Lookup word. 
    320313 
    321314    wblk = ur_blockPtr( ctx->ctx.wordBlk ); 
     
    331324            ++it; 
    332325        } 
     326        return -1; 
    333327    } 
    334328    else 
    335329    { 
    336         wrdN = _binarySearch( it, wblk->used, atom ); 
    337         if( wrdN > -1 ) 
    338             return wrdN; 
    339     } 
    340  
    341  
    342     // Not found - add new word. 
    343  
     330        return _binarySearch( it, wblk->used, atom ); 
     331    } 
     332} 
     333 
     334 
     335static int _internWord( UThread* ut, const UContext* ctx, UAtom atom ) 
     336{ 
     337    int wrdN; 
     338    UBlock* vblk; 
     339    UBlock* wblk; 
     340    UCell* it; 
     341 
     342    wblk = ur_blockPtr( ctx->ctx.wordBlk ); 
    344343    wrdN = wblk->used; 
    345344    UR_EXPAND_1( UCell, wblk, it ); 
     
    365364 
    366365    return wrdN; 
     366} 
     367 
     368 
     369/** 
     370  Add word to context if it does not already exist. 
     371  If added, the word is initialied as unset. 
     372 
     373  \return  Index of word in context. 
     374*/ 
     375int ur_internWordT( UThread* ut, const UContext* ctx, UAtom atom ) 
     376{ 
     377    int wrdN; 
     378 
     379    wrdN = _lookupNoSort( ut, ctx, atom ); 
     380    if( wrdN > -1 ) 
     381        return wrdN; 
     382 
     383    // Not found - add new word. 
     384    return _internWord( ut, ctx, atom ); 
    367385} 
    368386 
     
    571589    { 
    572590        --cit; 
    573         wrdN = ur_lookup( cit, atom ); 
     591        wrdN = _lookupNoSort( ut, cit, atom ); 
    574592        if( wrdN > -1 ) 
    575593            goto assign; 
     
    594612    // Word not found, so intern into current module (top of context stack). 
    595613    cit = ctop - 1; 
    596     wrdN = ur_internWord( cit, atom ); 
     614    wrdN = _internWord( ut, cit, atom ); 
    597615 
    598616assign: