aboutsummaryrefslogtreecommitdiffstats
path: root/cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/cache.c b/cache.c
index 2a9d547..bf3dc89 100644
--- a/cache.c
+++ b/cache.c
@@ -71,7 +71,8 @@ void cache_init(int block_size)
*/
struct cache_struct * get_cache_block(__u32 block)
{
- struct cache_struct *cs = &cache[1];
+ /* let's find it from the end, 'cause the endest is the freshest */
+ struct cache_struct *cs = cache_head.prev;
struct cache_struct *head, *last;
int i;
@@ -80,11 +81,15 @@ struct cache_struct * get_cache_block(__u32 block)
return NULL;
}
+ /* it's aleardy the freshest, so nothing we need do , just return it */
+ if ( cs->block == block )
+ return cs;
+
for ( i = 0; i < cache_entries; i ++ ) {
if ( cs->block == block )
break;
else
- cs = &cache[i + 1];
+ cs = cs->prev;
}
if ( i == cache_entries ) {