[libvirt] [PATCH] virsh: use faster bit search

Eric Blake eblake at redhat.com
Fri Jul 15 21:50:16 UTC 2011


Now that gnulib gives us ffs, we might as well use it.

* tools/virsh.c (vshCmddefGetData): Use ffs rather than
count_one_bits.
---
 tools/virsh.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index ef8dea3..0dcc66b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -32,6 +32,7 @@
 #include <inttypes.h>
 #include <signal.h>
 #include <poll.h>
+#include <strings.h>

 #include <libxml/parser.h>
 #include <libxml/tree.h>
@@ -57,7 +58,6 @@
 #include "configmake.h"
 #include "threads.h"
 #include "command.h"
-#include "count-one-bits.h"

 static char *progname;

@@ -12280,7 +12280,7 @@ vshCmddefGetData(const vshCmdDef *cmd, uint32_t *opts_need_arg,
         return NULL;

     /* Grab least-significant set bit */
-    i = count_one_bits(*opts_need_arg ^ (*opts_need_arg - 1)) - 1;
+    i = ffs(*opts_need_arg) - 1;
     opt = &cmd->opts[i];
     if (opt->type != VSH_OT_ARGV)
         *opts_need_arg &= ~(1 << i);
-- 
1.7.1




More information about the libvir-list mailing list