]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
bytecode_ptr: add shrink() member function
authorJustin Viiret <justin.viiret@intel.com>
Wed, 5 Apr 2017 06:58:53 +0000 (16:58 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 05:19:43 +0000 (15:19 +1000)
src/fdr/fdr_confirm_compile.cpp
src/util/bytecode_ptr.h

index d6eb6640bc77a79af3a8ce08ac9f6df7b69b2f0d..319141c4da3101feb71b9b1e6956f6af6c6fa26f 100644 (file)
@@ -337,6 +337,7 @@ bytecode_ptr<FDRConfirm> getFDRConfirm(const vector<hwlmLiteral> &lits,
     size_t actual_size = ROUNDUP_N((size_t)(ptr - fdrc_base),
                                    alignof(FDRConfirm));
     assert(actual_size <= size);
+    fdrc.shrink(actual_size);
 
     return fdrc;
 }
index ace5063cfa8d96a373e4ed573e1c199d7ddc88e2..15d3e2fe5371f8763b290cc2d95cc2e95857cbe7 100644 (file)
@@ -101,6 +101,19 @@ public:
         swap(alignment, other.alignment);
     }
 
+    /**
+     * \brief Reduces the apparent size of the memory region. Note that this
+     * does not reallocate and copy, it just changes the value returned by
+     * size().
+     */
+    void shrink(size_t size) {
+        if (size > bytes) {
+            assert(0);
+            throw std::logic_error("Must shrink to a smaller value");
+        }
+        bytes = size;
+    }
+
     /** \brief Returns size of the memory region in bytes. */
     size_t size() const { return bytes; }