From 4f9fa25ce09cc259cd41b3e12a74702ad1b08bcb Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 27 Jul 2021 18:13:36 +0800 Subject: [PATCH] common/bloom_filter: move bloom_filter::density() to .cc for faster compilation, also, bloom_filter::density() is not sitting in the critical paths, so no need to make it an inline function. Signed-off-by: Kefu Chai --- src/common/bloom_filter.cc | 15 +++++++++++++++ src/common/bloom_filter.hpp | 12 +----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/common/bloom_filter.cc b/src/common/bloom_filter.cc index 0845c3febbf9..9fb28efed68e 100644 --- a/src/common/bloom_filter.cc +++ b/src/common/bloom_filter.cc @@ -3,10 +3,25 @@ #include "common/bloom_filter.hpp" +#include +#include "include/intarith.h" + using ceph::bufferlist; using ceph::bufferptr; using ceph::Formatter; +double bloom_filter::density() const +{ + // TODO: use transform_reduce() in GCC-9 and up + unsigned set = std::accumulate( + bit_table_.begin(), + bit_table_.begin() + table_size_, + 0u, [](unsigned set, cell_type cell) { + return set + popcount(cell); + }); + return (double)set / (table_size_ * sizeof(cell_type) * CHAR_BIT); +} + void bloom_filter::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); diff --git a/src/common/bloom_filter.hpp b/src/common/bloom_filter.hpp index 3e75e4e60a7b..639516fe40e5 100644 --- a/src/common/bloom_filter.hpp +++ b/src/common/bloom_filter.hpp @@ -23,10 +23,8 @@ #define COMMON_BLOOM_FILTER_HPP #include -#include #include "include/encoding.h" -#include "include/intarith.h" #include "include/mempool.h" static const unsigned char bit_mask[CHAR_BIT] = { @@ -277,15 +275,7 @@ public: * .75 = 200% target insertions * 1.0 = all bits set... infinite insertions */ - inline double density() const - { - unsigned set = std::transform_reduce( - bit_table_.begin(), - bit_table_.begin() + table_size_, - 0, std::plus<>(), - popcount); - return (double)set / (table_size_ * sizeof(cell_type) * CHAR_BIT); - } + double density() const; virtual inline double approx_unique_element_count() const { // this is not a very good estimate; a better solution should have -- 2.47.3