From 803380c203dbe62a406db095a65254de96f5694e Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 19 Apr 2010 17:17:55 +0000 Subject: [PATCH] Speed up dm_bit_get_next with ffs(). --- WHATS_NEW_DM | 1 + libdm/datastruct/bitset.c | 13 +++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index eee757baa..5f22b63da 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.47 - ================================= + Speed up dm_bit_get_next with ffs(). Version 1.02.46 - 14th April 2010 ================================= diff --git a/libdm/datastruct/bitset.c b/libdm/datastruct/bitset.c index 953916259..e3c31d75c 100644 --- a/libdm/datastruct/bitset.c +++ b/libdm/datastruct/bitset.c @@ -52,18 +52,11 @@ void dm_bit_union(dm_bitset_t out, dm_bitset_t in1, dm_bitset_t in2) out[i] = in1[i] | in2[i]; } -/* - * FIXME: slow - */ -static inline int _test_word(uint32_t test, int bit) +static int _test_word(uint32_t test, int bit) { - while (bit < (int) DM_BITS_PER_INT) { - if (test & (0x1 << bit)) - return bit; - bit++; - } + int next_set_bit; - return -1; + return ((next_set_bit = ffs(test >> bit)) ? next_set_bit + bit - 1 : -1); } int dm_bit_get_next(dm_bitset_t bs, int last_bit)