From: Justin Viiret Date: Wed, 5 Apr 2017 06:58:53 +0000 (+1000) Subject: bytecode_ptr: add shrink() member function X-Git-Tag: v4.5.0^2~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4146059db033326c0d2da035702fb451ac66707;p=thirdparty%2Fvectorscan.git bytecode_ptr: add shrink() member function --- diff --git a/src/fdr/fdr_confirm_compile.cpp b/src/fdr/fdr_confirm_compile.cpp index d6eb6640..319141c4 100644 --- a/src/fdr/fdr_confirm_compile.cpp +++ b/src/fdr/fdr_confirm_compile.cpp @@ -337,6 +337,7 @@ bytecode_ptr getFDRConfirm(const vector &lits, size_t actual_size = ROUNDUP_N((size_t)(ptr - fdrc_base), alignof(FDRConfirm)); assert(actual_size <= size); + fdrc.shrink(actual_size); return fdrc; } diff --git a/src/util/bytecode_ptr.h b/src/util/bytecode_ptr.h index ace5063c..15d3e2fe 100644 --- a/src/util/bytecode_ptr.h +++ b/src/util/bytecode_ptr.h @@ -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; }