aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-05-25 07:10:12 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-05-25 07:10:12 +0800
commit61f27976b3d268ca28f618c0814f6482737084bc (patch)
tree70e79af30968a3696d0a037e3a3536b9471aead6
parentb23af34e29bf848e2e15d5b7c35da71166e28248 (diff)
downloaddevel-61f27976b3d268ca28f618c0814f6482737084bc.tar.gz
devel-61f27976b3d268ca28f618c0814f6482737084bc.tar.xz
devel-61f27976b3d268ca28f618c0814f6482737084bc.zip
make the cache searching more effective
-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 ) {