From f3a29906aa07d08bbde7ec02b93d02e25d805110 Mon Sep 17 00:00:00 2001 From: Nikhil Kalra Date: Wed, 12 Feb 2025 14:17:30 -0800 Subject: [mlir] BytecodeWriter: invoke `reserveExtraSpace` (#126953) Update `BytecodeWriter` to invoke `reserveExtraSpace` on the stream before writing to it. This will give clients implementing custom output streams the opportunity to allocate an appropriately sized buffer for the write. --- mlir/lib/Bytecode/Writer/BytecodeWriter.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mlir/lib/Bytecode') diff --git a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp index 2b4697434717..cc5aaed41651 100644 --- a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp +++ b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp @@ -613,6 +613,9 @@ private: } // namespace void EncodingEmitter::writeTo(raw_ostream &os) const { + // Reserve space in the ostream for the encoded contents. + os.reserveExtraSpace(size()); + for (auto &prevResult : prevResultList) os.write((const char *)prevResult.data(), prevResult.size()); os.write((const char *)currentResult.data(), currentResult.size()); -- cgit v1.2.3