Nucleus
Barry New list iteration in VFS f97b909 (3 years, 3 months ago)
diff --git a/vfs/direntry.c b/vfs/direntry.c
index 7a0b559..de7f02a 100644
--- a/vfs/direntry.c
+++ b/vfs/direntry.c
@@ -6,12 +6,6 @@
#include <nucleus/object.h>
#include <nucleus/vfs.h>
-/* Information for find callback */
-struct FindData {
- const char *name;
- DirEntry *result;
-};
-
static void direntry_delete(Object *);
/* Directory Entry object type */
@@ -41,32 +35,21 @@ direntry_delete(Object *obj)
put(entry->inode);
}
-/* Callback for finding a directory entry by name */
-static int
-compare_direntry_name(void *addr, void *data)
-{
- DirEntry *entry = addr;
- struct FindData *find = data;
- uint32_t hash = name_hash(find->name);
- if (__builtin_expect(!(entry->hash), 0))
- entry->hash = name_hash(entry->name);
- if (entry->hash != hash)
- return 0;
- if (strcmp(entry->name, find->name))
- return 0;
- find->result = get(entry);
- return 1;
-}
-
/* Find a Directory Entry by name in a list */
DirEntry *
find_direntry(ObjectList *list, const char *name)
{
- struct FindData data = {
- .name = name,
- .result = NULL,
- };
- iterate(list, compare_direntry_name, &data);
- return data.result;
+ DirEntry *entry;
+ uint32_t hash = name_hash(name);
+ foreach (list, entry) {
+ if (__builtin_expect(!(entry->hash), 0))
+ entry->hash = name_hash(entry->name);
+ if (entry->hash != hash)
+ continue;
+ if (strcmp(entry->name, name))
+ continue;
+ break;
+ }
+ return entry;
}