diff options
author | 2024-12-13 17:29:18 -0800 | |
---|---|---|
committer | 2024-12-13 17:29:18 -0800 | |
commit | 7b1f850c50427ff38c20c83721c2e7aa173e62c2 (patch) | |
tree | 92f02a12a16318cde6d9a3b3761ca2c0040ce557 /libs/androidfw/BigBuffer.cpp | |
parent | 3f4c4881a31f0a24979df539b9d1e9c557a3619d (diff) | |
parent | 10e260fc86f8b879e9a88610994344f30bea7520 (diff) |
Merge "Merge 24Q4 into AOSP main" into main
Diffstat (limited to 'libs/androidfw/BigBuffer.cpp')
-rw-r--r-- | libs/androidfw/BigBuffer.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/libs/androidfw/BigBuffer.cpp b/libs/androidfw/BigBuffer.cpp index bedfc49a1b0d..43b56c32fb79 100644 --- a/libs/androidfw/BigBuffer.cpp +++ b/libs/androidfw/BigBuffer.cpp @@ -17,8 +17,8 @@ #include <androidfw/BigBuffer.h> #include <algorithm> +#include <iterator> #include <memory> -#include <vector> #include "android-base/logging.h" @@ -78,10 +78,27 @@ void* BigBuffer::NextBlock(size_t* out_size) { std::string BigBuffer::to_string() const { std::string result; + result.reserve(size_); for (const Block& block : blocks_) { result.append(block.buffer.get(), block.buffer.get() + block.size); } return result; } +void BigBuffer::AppendBuffer(BigBuffer&& buffer) { + std::move(buffer.blocks_.begin(), buffer.blocks_.end(), std::back_inserter(blocks_)); + size_ += buffer.size_; + buffer.blocks_.clear(); + buffer.size_ = 0; +} + +void BigBuffer::BackUp(size_t count) { + Block& block = blocks_.back(); + block.size -= count; + size_ -= count; + // BigBuffer is supposed to always give zeroed memory, but backing up usually means + // something has been already written into the block. Erase it. + std::fill_n(block.buffer.get() + block.size, count, 0); +} + } // namespace android |