From 671f5c6393ac668acb639273135b1187ef931f89 Mon Sep 17 00:00:00 2001 From: nvt-se Date: Fri, 4 Jul 2008 02:54:30 +0000 Subject: [PATCH] Major performance boost to directory listings and non-cached file openings. --- core/cfs/cfs-coffee.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/cfs/cfs-coffee.c b/core/cfs/cfs-coffee.c index 7cbcc173c..d605ca8b6 100644 --- a/core/cfs/cfs-coffee.c +++ b/core/cfs/cfs-coffee.c @@ -248,7 +248,10 @@ find_file(const char *name) } else if(COFFEE_PAGE_OBSOLETE(hdr)) { page += hdr.max_pages; } else { - page++; + /* It follows from the properties of the page allocation algorithm + that if a free page is encountered, the rest of the sector is + also free. */ + page = (page + COFFEE_PAGES_PER_SECTOR) & ~(COFFEE_PAGES_PER_SECTOR - 1); } watchdog_periodic(); } while(page < COFFEE_PAGE_COUNT); @@ -906,8 +909,11 @@ cfs_readdir(struct cfs_dir *dir, struct cfs_dirent *entry) page += hdr.max_pages; *(uint16_t *)dir->dummy_space = page; return 0; + } else if (COFFEE_PAGE_FREE(hdr)) { + page = (page + COFFEE_PAGES_PER_SECTOR) & ~(COFFEE_PAGES_PER_SECTOR - 1); + } else { + page += hdr.max_pages; } - page += COFFEE_PAGE_OBSOLETE(hdr) ? hdr.max_pages : 1; } return -1;