Skip to content

Commit 9013e3f

Browse files
committed
optimize the file search process
1 parent d7e0c9b commit 9013e3f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

dir.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
6262
for (; remained_nr_files && ei < SIMPLEFS_MAX_EXTENTS; ei++) {
6363
if (eblock->extents[ei].ee_start == 0)
6464
continue;
65-
65+
int ei_nr = eblock->extents[ei].nr_files;
6666
/* Iterate over blocks in one extent */
67-
for (bi = 0; bi < eblock->extents[ei].ee_len && remained_nr_files;
67+
for (bi = 0;
68+
bi < eblock->extents[ei].ee_len && remained_nr_files && ei_nr;
6869
bi++) {
6970
bh2 = sb_bread(sb, eblock->extents[ei].ee_start + bi);
7071
if (!bh2) {
@@ -86,6 +87,7 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
8687
offset--;
8788
} else {
8889
remained_nr_files--;
90+
ei_nr--;
8991
if (!dir_emit(ctx, dblock->files[fi].filename,
9092
SIMPLEFS_FILENAME_LEN,
9193
dblock->files[fi].inode, DT_UNKNOWN)) {

0 commit comments

Comments
 (0)