From: Kefu Chai Date: Fri, 16 Aug 2019 08:10:02 +0000 (+0800) Subject: denc: add fallback for the O(n) legacy of std::list::size(). X-Git-Tag: v15.1.0~1804^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7aae20cdf2762323033e46114e49756d7de96ba0;p=ceph.git denc: add fallback for the O(n) legacy of std::list::size(). Signed-off-by: Kefu Chai --- diff --git a/src/include/denc.h b/src/include/denc.h index ab88aac4b8a..14db8380c70 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -939,12 +939,16 @@ namespace _denc { static void bound_encode(const container& s, size_t& p, uint64_t f = 0) { p += sizeof(uint32_t); if constexpr (traits::bounded) { - const auto elem_num = s.size(); +#if _GLIBCXX_USE_CXX11_ABI // 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) { + if (const auto elem_num = s.size(); elem_num > 0) { +#else + if (!s.empty()) { + const auto elem_num = s.size(); +#endif // STL containers use weird element types like std::pair; // cast to something we have denc_traits for. size_t elem_size = 0;