From 793807b07e20e5e607393f52bf52c4b3f1308887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Tue, 18 Jan 2005 21:57:52 +0000 Subject: [PATCH] Re-worked with bsearch. * mountlist.c: (ignore_mount_entry): Re-worked with bsearch. --- sysdeps/common/ChangeLog | 4 ++++ sysdeps/common/mountlist.c | 34 ++++++++++++++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/sysdeps/common/ChangeLog b/sysdeps/common/ChangeLog index 48c01e96..aeba1c4e 100644 --- a/sysdeps/common/ChangeLog +++ b/sysdeps/common/ChangeLog @@ -1,3 +1,7 @@ +2005-01-18 Benoît Dejean + + * mountlist.c: (ignore_mount_entry): Re-worked with bsearch. + 2004-12-09 Benoît Dejean * mountlist.c: (ignore_mount_entry): Ignores "unkown" file system type. diff --git a/sysdeps/common/mountlist.c b/sysdeps/common/mountlist.c index 30ae0b6b..8cf21516 100644 --- a/sysdeps/common/mountlist.c +++ b/sysdeps/common/mountlist.c @@ -21,6 +21,7 @@ #include #include +#include #include #if defined(STDC_HEADERS) || defined(HAVE_STRING_H) @@ -535,31 +536,28 @@ read_filesystem_list (void) static gboolean ignore_mount_entry(const struct mount_entry *me) { + /* keep sorted */ static const char ignored[][12] = { + "autofs", + "binfmt_misc", + "devpts", + "mntfs", + "none", + "openpromfs", "proc", "procfs", - "autofs", - "sysfs", - "usbfs", - "none", - "devpts", - "usbdevfs", - "binfmt_misc", "supermount", - "mntfs", - "openpromfs", - "unknown" + "sysfs", + "unknown", + "usbdevfs", + "usbfs" }; - const char (*i)[12] = &ignored[0]; + typedef int (*Comparator)(const void*, const void*); - while(i != (&ignored[0] + G_N_ELEMENTS(ignored))) { - if(strcmp(*i, me->me_type) == 0) - return TRUE; - ++i; - } - - return FALSE; + return bsearch(me->me_type, + ignored, G_N_ELEMENTS(ignored), sizeof ignored[0], + (Comparator) strcmp) != NULL; }