diff options
author | crupest <crupest@outlook.com> | 2024-06-01 17:09:44 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-06-08 17:01:55 +0800 |
commit | d1f409530db6f9b712fd672c4c3154cac7eebad1 (patch) | |
tree | 1e48a3e2ff14e66aac2503a74df28cca7d85d02c /src/common/Buffer.cpp | |
parent | ad796a167e33b54c7fa23ea21c73d57dba4fc928 (diff) | |
download | cru-d1f409530db6f9b712fd672c4c3154cac7eebad1.tar.gz cru-d1f409530db6f9b712fd672c4c3154cac7eebad1.tar.bz2 cru-d1f409530db6f9b712fd672c4c3154cac7eebad1.zip |
HALF WORK: refactor something and implement part of subprocess.
Diffstat (limited to 'src/common/Buffer.cpp')
-rw-r--r-- | src/common/Buffer.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
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; |