From b04679b42994049a5d52ba9879c8ee34c0b85318 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 5 Jul 2017 17:10:59 +0200 Subject: [PATCH] util/WritableBuffer: add method MoveFront() --- src/util/WritableBuffer.hxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx index fc3b872ab..e36f24e56 100644 --- a/src/util/WritableBuffer.hxx +++ b/src/util/WritableBuffer.hxx @@ -235,6 +235,20 @@ struct WritableBuffer { data += n; size -= n; } + + /** + * Move the front pointer to the given address, and adjust the + * size attribute to retain the old end address. + */ + void MoveFront(pointer_type new_data) { +#ifndef NDEBUG + assert(IsNull() == (new_data == nullptr)); + assert(new_data <= end()); +#endif + + size = end() - new_data; + data = new_data; + } }; #endif