]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async: use bitset<> to do the popcnt 18681/head
authorKefu Chai <kchai@redhat.com>
Thu, 2 Nov 2017 07:20:24 +0000 (15:20 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 2 Nov 2017 07:22:11 +0000 (15:22 +0800)
libstdc++ uses popcnt to count the bits. it's faster and simpler.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/msg/async/dpdk/dpdk_rte.cc

index 6510df103b201f71ab971a6ab454b025ce9037cb..89a69e527539e8e15026c710a0361ab9c1f49ebb 100644 (file)
@@ -16,6 +16,8 @@
  * under the License.
  */
 
+#include <bitset>
+
 #include <rte_config.h>
 #include <rte_common.h>
 #include <rte_ethdev.h>
@@ -40,10 +42,7 @@ namespace dpdk {
 
   static int bitcount(unsigned n)
   {
-    unsigned int c =0 ;
-    for (c = 0; n; ++c)
-      n &= (n -1);
-    return c;
+    return std::bitset<CHAR_BIT * sizeof(n)>{n}.count();
   }
 
   int eal::init(CephContext *c)