Message ID | 38D0DA1A-A001-4AD1-9F63-E4CEE4EC4610@dlhnet.de |
---|---|
State | New |
Headers | show |
On 25 February 2013 12:50, Peter Lieven <pl@dlhnet.de> wrote: > sth like this? > > diff --git a/page_cache.c b/page_cache.c > index 376f1db..04205ee 100644 > --- a/page_cache.c > +++ b/page_cache.c > @@ -196,21 +196,19 @@ int64_t cache_resize(PageCache *cache, int64_t new_num_pages) > /* check for collision, if there is, keep MRU page */ > new_it = cache_get_by_addr(new_cache, old_it->it_addr); > if (new_it->it_data) { > - /* keep the MRU page */ > if (new_it->it_age >= old_it->it_age) { > g_free(old_it->it_data); > - } else { > - g_free(new_it->it_data); > - new_it->it_data = old_it->it_data; > - new_it->it_age = old_it->it_age; > - new_it->it_addr = old_it->it_addr; > + continue; > } > - } else { > - cache_insert(new_cache, old_it->it_addr, old_it->it_data); > } > + g_free(new_it->it_data); > + new_it->it_data = old_it->it_data; > + new_it->it_age = old_it->it_age; > + new_it->it_addr = old_it->it_addr; > } > } > > + g_free(cache->page_cache); > cache->page_cache = new_cache->page_cache; > cache->max_num_items = new_cache->max_num_items; > cache->num_items = new_cache->num_items; Yeah, more or less. You could roll the two if () conditions into "if (new_it->it_data && new_it->it_age >= old_it->it_age)" but that's just a style thing. -- PMM
diff --git a/page_cache.c b/page_cache.c index 376f1db..04205ee 100644 --- a/page_cache.c +++ b/page_cache.c @@ -196,21 +196,19 @@ int64_t cache_resize(PageCache *cache, int64_t new_num_pages) /* check for collision, if there is, keep MRU page */ new_it = cache_get_by_addr(new_cache, old_it->it_addr); if (new_it->it_data) { - /* keep the MRU page */ if (new_it->it_age >= old_it->it_age) { g_free(old_it->it_data); - } else { - g_free(new_it->it_data); - new_it->it_data = old_it->it_data; - new_it->it_age = old_it->it_age; - new_it->it_addr = old_it->it_addr; + continue; } - } else { - cache_insert(new_cache, old_it->it_addr, old_it->it_data); } + g_free(new_it->it_data); + new_it->it_data = old_it->it_data; + new_it->it_age = old_it->it_age; + new_it->it_addr = old_it->it_addr; } } + g_free(cache->page_cache); cache->page_cache = new_cache->page_cache; cache->max_num_items = new_cache->max_num_items; cache->num_items = new_cache->num_items;