]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
denc: add fallback for the O(n) legacy of std::list::size().
authorKefu Chai <kchai@redhat.com>
Fri, 16 Aug 2019 08:10:02 +0000 (16:10 +0800)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 16 Aug 2019 11:56:13 +0000 (07:56 -0400)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/include/denc.h

index ab88aac4b8a8f8dab039d75b5bdbec9fecc4d482..14db8380c70cdd4182eaa707b147d9181793c448 100644 (file)
@@ -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<const K, V>;
           // cast to something we have denc_traits for.
           size_t elem_size = 0;