From 67779e0c0af17a4c9dbbf75856d24c6ceb2c5dcf Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Mon, 3 Apr 2017 17:38:26 +1000 Subject: [PATCH] bytecode_ptr: some small improvements --- src/util/bytecode_ptr.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util/bytecode_ptr.h b/src/util/bytecode_ptr.h index f55f78ec..1242e23d 100644 --- a/src/util/bytecode_ptr.h +++ b/src/util/bytecode_ptr.h @@ -35,7 +35,9 @@ #define UTIL_BYTECODE_PTR_H #include "util/alloc.h" +#include "util/operators.h" +#include // std::max #include #include @@ -47,7 +49,7 @@ namespace ue2 { * This is intended to be used for flat aligned memory regions that will * eventually end up copied into the Hyperscan bytecode. */ -template class bytecode_ptr { +template class bytecode_ptr : totally_ordered> { public: bytecode_ptr() = default; explicit bytecode_ptr(size_t size, size_t align = alignof(T)) @@ -81,7 +83,14 @@ public: return std::shared_ptr(ptr.release(), d); } - void reset(T* p = nullptr) { ptr.reset(p); } + void reset(T *p = nullptr) { ptr.reset(p); } + + T *release() { + auto *p = ptr.release(); + bytes = 0; + alignment = 0; + return p; + } void swap(bytecode_ptr &other) { using std::swap; @@ -97,11 +106,7 @@ public: size_t align() const { return alignment; } bool operator==(const bytecode_ptr &a) const { return ptr == a.ptr; } - bool operator!=(const bytecode_ptr &a) const { return ptr != a.ptr; } bool operator<(const bytecode_ptr &a) const { return ptr < a.ptr; } - bool operator<=(const bytecode_ptr &a) const { return ptr <= a.ptr; } - bool operator>(const bytecode_ptr &a) const { return ptr > a.ptr; } - bool operator>=(const bytecode_ptr &a) const { return ptr >= a.ptr; } private: /** \brief Deleter function for std::unique_ptr. */