From d1f409530db6f9b712fd672c4c3154cac7eebad1 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 1 Jun 2024 17:09:44 +0800 Subject: HALF WORK: refactor something and implement part of subprocess. --- src/common/Buffer.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/common/Buffer.cpp') diff --git a/src/common/Buffer.cpp b/src/common/Buffer.cpp index 67e67735..49a0f8ae 100644 --- a/src/common/Buffer.cpp +++ b/src/common/Buffer.cpp @@ -89,6 +89,15 @@ Index Buffer::PushFront(const std::byte* other, Index other_size, return copy_size; } +bool Buffer::PushBack(std::byte b) { + if (IsUsedReachEnd()) { + return false; + } + ptr_[used_end_] = b; + used_end_++; + return true; +} + Index Buffer::PushBack(const std::byte* other, Index other_size, bool use_memmove) { auto copy_size = std::min(size_ - used_end_, other_size); @@ -138,6 +147,16 @@ Index Buffer::PopEnd(std::byte* buffer, Index size, bool use_memmove) { return pop_size; } +std::byte* Buffer::Detach(Index* size) { + auto ptr = this->ptr_; + if (size) { + *size = this->size_; + } + this->ptr_ = nullptr; + this->size_ = this->used_begin_ = this->used_end_ = 0; + return ptr; +} + void Buffer::Copy_(const Buffer& other) { if (other.ptr_ == nullptr) { ptr_ = nullptr; -- cgit v1.2.3