]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common, test: use std::popcount() when appropriate
authorKefu Chai <tchaikov@gmail.com>
Sun, 21 Aug 2022 16:37:12 +0000 (00:37 +0800)
committerKefu Chai <tchaikov@gmail.com>
Mon, 22 Aug 2022 10:03:59 +0000 (18:03 +0800)
prefer the facilities provided by standard library over the homebrew
ones for better readability and maintainability.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/common/bloom_filter.cc
src/test/erasure-code/TestErasureCodeShec_arguments.cc

index 9fb28efed68e5d321bf74da695594f781a37a530..4bacb5473ae36952299550f492fe8d68df06c4b1 100644 (file)
@@ -3,8 +3,8 @@
 
 #include "common/bloom_filter.hpp"
 
+#include <bit>
 #include <numeric>
-#include "include/intarith.h"
 
 using ceph::bufferlist;
 using ceph::bufferptr;
@@ -17,7 +17,7 @@ double bloom_filter::density() const
     bit_table_.begin(),
     bit_table_.begin() + table_size_,
     0u, [](unsigned set, cell_type cell) {
-      return set + popcount(cell);
+      return set + std::popcount(cell);
     });
   return (double)set / (table_size_ * sizeof(cell_type) * CHAR_BIT);
 }
index bd387654ff532a32766a2ee8479f3c62626bf074..edf731ee28740335486211de667f490276000dba 100644 (file)
@@ -18,6 +18,7 @@
 
 // SUMMARY: shec's gtest for each argument of minimum_to_decode()/decode()
 
+#include <bit>
 #include <errno.h>
 #include <stdlib.h>
 
@@ -56,10 +57,10 @@ void create_table_shec432() {
   set<set<int> > table_value;
 
   for (int want_count = 0; want_count < 7; ++want_count) {
-    for (int want = 1; want < (1<<7); ++want) {
+    for (unsigned want = 1; want < (1<<7); ++want) {
       table_key.clear();
       table_value.clear();
-      if (__builtin_popcount(want) != want_count) {
+      if (std::popcount(want) != want_count) {
         continue;
       }
       {
@@ -70,12 +71,12 @@ void create_table_shec432() {
         }
       }
       vector<int> vec;
-      for (int avails = 0; avails < (1<<7); ++avails) {
+      for (unsigned avails = 0; avails < (1<<7); ++avails) {
         if (want & avails) {
           continue;
         }
-        if (__builtin_popcount(avails) == 2 &&
-            __builtin_popcount(want) == 1) {
+        if (std::popcount(avails) == 2 &&
+            std::popcount(want) == 1) {
           if ((want | avails) == getint(0,1,5) ||
               (want | avails) == getint(2,3,6)) {
             vec.push_back(avails);
@@ -83,11 +84,11 @@ void create_table_shec432() {
         }
       }
       
-      for (int avails = 0; avails < (1<<7); ++avails) {
+      for (unsigned avails = 0; avails < (1<<7); ++avails) {
         if (want & avails) {
           continue;
         }
-        if (__builtin_popcount(avails) == 4) {
+        if (std::popcount(avails) == 4) {
           if ((avails) == getint(0,1,2,3) ||
               (avails) == getint(0,1,2,4) ||
               (avails) == getint(0,1,2,6) ||