From: Radoslaw Zarzynski Date: Wed, 17 Oct 2018 12:28:48 +0000 (+0200) Subject: denc: slightly optimize container_base::bound_encode. X-Git-Tag: v15.1.0~1804^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f1b61c548b61cad4bec70b835f67066c47cad14a;p=ceph.git denc: slightly optimize container_base::bound_encode. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/include/denc.h b/src/include/denc.h index 41b333d39dac..ab88aac4b8a8 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -939,7 +939,12 @@ namespace _denc { static void bound_encode(const container& s, size_t& p, uint64_t f = 0) { p += sizeof(uint32_t); if constexpr (traits::bounded) { - if (!s.empty()) { + const auto elem_num = s.size(); + // intensionally not calling container's empty() method to not prohibit + // compiler from optimizing the check if it and the ::size() operate on + // different memory (observed when std::list::empty() works on pointers, + // not the size field). + if (elem_num) { // STL containers use weird element types like std::pair; // cast to something we have denc_traits for. size_t elem_size = 0; @@ -948,7 +953,7 @@ namespace _denc { } else { denc(static_cast(*s.begin()), elem_size); } - p += sizeof(uint32_t) + elem_size * s.size(); + p += sizeof(uint32_t) + elem_size * elem_num; } } else { for (const T& e : s) {