]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
denc: slightly optimize container_base::bound_encode.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 17 Oct 2018 12:28:48 +0000 (14:28 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 16 Aug 2019 11:56:12 +0000 (07:56 -0400)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/include/denc.h

index 41b333d39dac76edb039c3c00bf190120cd4c51b..ab88aac4b8a8f8dab039d75b5bdbec9fecc4d482 100644 (file)
@@ -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<const K, V>;
           // cast to something we have denc_traits for.
           size_t elem_size = 0;
@@ -948,7 +953,7 @@ namespace _denc {
           } else {
             denc(static_cast<const T&>(*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) {