From 844260f3a2a065298c94ceee8c1d9774fdbf825d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 22 Aug 2022 00:37:12 +0800 Subject: [PATCH] common, test: use std::popcount() when appropriate prefer the facilities provided by standard library over the homebrew ones for better readability and maintainability. Signed-off-by: Kefu Chai --- src/common/bloom_filter.cc | 4 ++-- .../erasure-code/TestErasureCodeShec_arguments.cc | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/common/bloom_filter.cc b/src/common/bloom_filter.cc index 9fb28efed68e5..4bacb5473ae36 100644 --- a/src/common/bloom_filter.cc +++ b/src/common/bloom_filter.cc @@ -3,8 +3,8 @@ #include "common/bloom_filter.hpp" +#include #include -#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); } diff --git a/src/test/erasure-code/TestErasureCodeShec_arguments.cc b/src/test/erasure-code/TestErasureCodeShec_arguments.cc index bd387654ff532..edf731ee28740 100644 --- a/src/test/erasure-code/TestErasureCodeShec_arguments.cc +++ b/src/test/erasure-code/TestErasureCodeShec_arguments.cc @@ -18,6 +18,7 @@ // SUMMARY: shec's gtest for each argument of minimum_to_decode()/decode() +#include #include #include @@ -56,10 +57,10 @@ void create_table_shec432() { set > 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 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) || -- 2.39.5