[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.
This commit is contained in:
parent
be15811c46
commit
f2f9754542
|
@ -426,7 +426,7 @@
|
||||||
memory = manager->memory;
|
memory = manager->memory;
|
||||||
|
|
||||||
/* now discard all caches */
|
/* now discard all caches */
|
||||||
for (idx = manager->num_caches; idx-- > 0; )
|
for ( idx = manager->num_caches; idx-- > 0; )
|
||||||
{
|
{
|
||||||
FTC_Cache cache = manager->caches[idx];
|
FTC_Cache cache = manager->caches[idx];
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@
|
||||||
FT_LOCAL_DEF( void )
|
FT_LOCAL_DEF( void )
|
||||||
FTC_Manager_Compress( FTC_Manager manager )
|
FTC_Manager_Compress( FTC_Manager manager )
|
||||||
{
|
{
|
||||||
FTC_Node node, first;
|
FTC_Node node, prev, first;
|
||||||
|
|
||||||
|
|
||||||
if ( !manager )
|
if ( !manager )
|
||||||
|
@ -557,20 +557,16 @@
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* go to last node -- it's a circular list */
|
/* go to last node -- it's a circular list */
|
||||||
node = FTC_NODE_PREV( first );
|
prev = FTC_NODE_PREV( first );
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
FTC_Node prev;
|
node = prev;
|
||||||
|
prev = FTC_NODE_PREV( node );
|
||||||
|
|
||||||
prev = ( node == first ) ? NULL : FTC_NODE_PREV( node );
|
|
||||||
|
|
||||||
if ( node->ref_count <= 0 )
|
if ( node->ref_count <= 0 )
|
||||||
ftc_node_destroy( node, manager );
|
ftc_node_destroy( node, manager );
|
||||||
|
|
||||||
node = prev;
|
} while ( node != first && manager->cur_weight > manager->max_weight );
|
||||||
|
|
||||||
} while ( node && manager->cur_weight > manager->max_weight );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -633,20 +629,20 @@
|
||||||
FT_UInt count )
|
FT_UInt count )
|
||||||
{
|
{
|
||||||
FTC_Node first = manager->nodes_list;
|
FTC_Node first = manager->nodes_list;
|
||||||
FTC_Node node;
|
FTC_Node prev, node;
|
||||||
FT_UInt result;
|
FT_UInt result = 0;
|
||||||
|
|
||||||
|
|
||||||
/* try to remove `count' nodes from the list */
|
/* try to remove `count' nodes from the list */
|
||||||
if ( !first ) /* empty list! */
|
if ( !first || !count )
|
||||||
return 0;
|
return result;
|
||||||
|
|
||||||
/* go to last node - it's a circular list */
|
/* go to last node -- it's a circular list */
|
||||||
node = FTC_NODE_PREV(first);
|
prev = FTC_NODE_PREV( first );
|
||||||
for ( result = 0; result < count; )
|
do
|
||||||
{
|
{
|
||||||
FTC_Node prev = FTC_NODE_PREV( node );
|
node = prev;
|
||||||
|
prev = FTC_NODE_PREV( node );
|
||||||
|
|
||||||
/* don't touch locked nodes */
|
/* don't touch locked nodes */
|
||||||
if ( node->ref_count <= 0 )
|
if ( node->ref_count <= 0 )
|
||||||
|
@ -654,13 +650,9 @@
|
||||||
ftc_node_destroy( node, manager );
|
ftc_node_destroy( node, manager );
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
|
} while ( node != first && result < count );
|
||||||
|
|
||||||
if ( node == first )
|
return result;
|
||||||
break;
|
|
||||||
|
|
||||||
node = prev;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -329,29 +329,23 @@
|
||||||
FTC_MruNode_CompareFunc selection,
|
FTC_MruNode_CompareFunc selection,
|
||||||
FT_Pointer key )
|
FT_Pointer key )
|
||||||
{
|
{
|
||||||
FTC_MruNode first, node, next;
|
FTC_MruNode first = list->nodes;
|
||||||
|
FTC_MruNode node, next;
|
||||||
|
|
||||||
|
|
||||||
first = list->nodes;
|
if ( !first || !selection )
|
||||||
while ( first && ( !selection || selection( first, key ) ) )
|
return;
|
||||||
|
|
||||||
|
next = first;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
FTC_MruList_Remove( list, first );
|
node = next;
|
||||||
first = list->nodes;
|
next = node->next;
|
||||||
}
|
|
||||||
|
|
||||||
if ( first )
|
if ( selection( node, key ) )
|
||||||
{
|
FTC_MruList_Remove( list, node );
|
||||||
node = first->next;
|
|
||||||
while ( node != first )
|
|
||||||
{
|
|
||||||
next = node->next;
|
|
||||||
|
|
||||||
if ( selection( node, key ) )
|
} while ( next != first );
|
||||||
FTC_MruList_Remove( list, node );
|
|
||||||
|
|
||||||
node = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue