freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype][master] [cache] Revise list cleansing.


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] [cache] Revise list cleansing.
Date: Thu, 04 May 2023 03:04:06 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

  • f2f97545
    by Alexei Podtelezhnikov at 2023-05-03T23:02:04-04:00
    [cache] Revise list cleansing.
    
    * src/cache/ftcmru.c (FTC_MruList_RemoveSelection): Use one loop to
    do it.
    * src/cache/ftcmanag.c (FTC_Manager_Compress, FTC_Manager_FlushN):
    Streamline loops.
    

2 changed files:

Changes:

  • src/cache/ftcmanag.c
    ... ... @@ -426,7 +426,7 @@
    426 426
         memory = manager->memory;
    
    427 427
     
    
    428 428
         /* now discard all caches */
    
    429
    -    for (idx = manager->num_caches; idx-- > 0; )
    
    429
    +    for ( idx = manager->num_caches; idx-- > 0; )
    
    430 430
         {
    
    431 431
           FTC_Cache  cache = manager->caches[idx];
    
    432 432
     
    
    ... ... @@ -537,7 +537,7 @@
    537 537
       FT_LOCAL_DEF( void )
    
    538 538
       FTC_Manager_Compress( FTC_Manager  manager )
    
    539 539
       {
    
    540
    -    FTC_Node   node, first;
    
    540
    +    FTC_Node   node, prev, first;
    
    541 541
     
    
    542 542
     
    
    543 543
         if ( !manager )
    
    ... ... @@ -557,20 +557,16 @@
    557 557
           return;
    
    558 558
     
    
    559 559
         /* go to last node -- it's a circular list */
    
    560
    -    node = FTC_NODE_PREV( first );
    
    560
    +    prev = FTC_NODE_PREV( first );
    
    561 561
         do
    
    562 562
         {
    
    563
    -      FTC_Node  prev;
    
    564
    -
    
    565
    -
    
    566
    -      prev = ( node == first ) ? NULL : FTC_NODE_PREV( node );
    
    563
    +      node = prev;
    
    564
    +      prev = FTC_NODE_PREV( node );
    
    567 565
     
    
    568 566
           if ( node->ref_count <= 0 )
    
    569 567
             ftc_node_destroy( node, manager );
    
    570 568
     
    
    571
    -      node = prev;
    
    572
    -
    
    573
    -    } while ( node && manager->cur_weight > manager->max_weight );
    
    569
    +    } while ( node != first && manager->cur_weight > manager->max_weight );
    
    574 570
       }
    
    575 571
     
    
    576 572
     
    
    ... ... @@ -633,20 +629,20 @@
    633 629
                           FT_UInt      count )
    
    634 630
       {
    
    635 631
         FTC_Node  first = manager->nodes_list;
    
    636
    -    FTC_Node  node;
    
    637
    -    FT_UInt   result;
    
    632
    +    FTC_Node  prev, node;
    
    633
    +    FT_UInt   result = 0;
    
    638 634
     
    
    639 635
     
    
    640 636
         /* try to remove `count' nodes from the list */
    
    641
    -    if ( !first )  /* empty list! */
    
    642
    -      return 0;
    
    637
    +    if ( !first || !count )
    
    638
    +      return result;
    
    643 639
     
    
    644
    -    /* go to last node - it's a circular list */
    
    645
    -    node = FTC_NODE_PREV(first);
    
    646
    -    for ( result = 0; result < count; )
    
    640
    +    /* go to last node -- it's a circular list */
    
    641
    +    prev = FTC_NODE_PREV( first );
    
    642
    +    do
    
    647 643
         {
    
    648
    -      FTC_Node  prev = FTC_NODE_PREV( node );
    
    649
    -
    
    644
    +      node = prev;
    
    645
    +      prev = FTC_NODE_PREV( node );
    
    650 646
     
    
    651 647
           /* don't touch locked nodes */
    
    652 648
           if ( node->ref_count <= 0 )
    
    ... ... @@ -654,13 +650,9 @@
    654 650
             ftc_node_destroy( node, manager );
    
    655 651
             result++;
    
    656 652
           }
    
    653
    +    } while ( node != first && result < count );
    
    657 654
     
    
    658
    -      if ( node == first )
    
    659
    -        break;
    
    660
    -
    
    661
    -      node = prev;
    
    662
    -    }
    
    663
    -    return  result;
    
    655
    +    return result;
    
    664 656
       }
    
    665 657
     
    
    666 658
     
    

  • src/cache/ftcmru.c
    ... ... @@ -329,29 +329,23 @@
    329 329
                                    FTC_MruNode_CompareFunc  selection,
    
    330 330
                                    FT_Pointer               key )
    
    331 331
       {
    
    332
    -    FTC_MruNode  first, node, next;
    
    332
    +    FTC_MruNode  first = list->nodes;
    
    333
    +    FTC_MruNode  node, next;
    
    333 334
     
    
    334 335
     
    
    335
    -    first = list->nodes;
    
    336
    -    while ( first && ( !selection || selection( first, key ) ) )
    
    337
    -    {
    
    338
    -      FTC_MruList_Remove( list, first );
    
    339
    -      first = list->nodes;
    
    340
    -    }
    
    336
    +    if ( !first || !selection )
    
    337
    +      return;
    
    341 338
     
    
    342
    -    if ( first )
    
    339
    +    next = first;
    
    340
    +    do
    
    343 341
         {
    
    344
    -      node = first->next;
    
    345
    -      while ( node != first )
    
    346
    -      {
    
    347
    -        next = node->next;
    
    342
    +      node = next;
    
    343
    +      next = node->next;
    
    348 344
     
    
    349
    -        if ( selection( node, key ) )
    
    350
    -          FTC_MruList_Remove( list, node );
    
    345
    +      if ( selection( node, key ) )
    
    346
    +        FTC_MruList_Remove( list, node );
    
    351 347
     
    
    352
    -        node = next;
    
    353
    -      }
    
    354
    -    }
    
    348
    +    } while ( next != first );
    
    355 349
       }
    
    356 350
     
    
    357 351
     
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]