diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index b962c99e1d5..09c914fab07 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -163,7 +163,10 @@ class CallData { grpc_linked_mdelem accept_encoding_storage_; grpc_linked_mdelem accept_stream_encoding_storage_; grpc_slice_buffer slices_; /**< Buffers up input slices to be compressed */ - absl::optional replacement_stream_; + // Allocate space for the replacement stream + std::aligned_storage::type + replacement_stream_; grpc_closure* original_send_message_on_complete_ = nullptr; grpc_closure send_message_on_complete_; grpc_closure on_send_message_next_done_; @@ -334,9 +337,11 @@ void CallData::FinishSendMessage(grpc_call_element* elem) { grpc_slice_buffer_destroy_internal(&tmp); // Swap out the original byte stream with our new one and send the // batch down. - replacement_stream_.emplace(&slices_, send_flags); + new (&replacement_stream_) + grpc_core::SliceBufferByteStream(&slices_, send_flags); send_message_batch_->payload->send_message.send_message.reset( - &replacement_stream_.value()); + reinterpret_cast( + &replacement_stream_)); original_send_message_on_complete_ = send_message_batch_->on_complete; send_message_batch_->on_complete = &send_message_on_complete_; SendMessageBatchContinue(elem); diff --git a/src/core/lib/transport/byte_stream.h b/src/core/lib/transport/byte_stream.h index ffa9b47c20d..6988ab843b2 100644 --- a/src/core/lib/transport/byte_stream.h +++ b/src/core/lib/transport/byte_stream.h @@ -72,7 +72,7 @@ class ByteStream : public Orphanable { : length_(length), flags_(flags) {} private: - uint32_t length_; + const uint32_t length_; uint32_t flags_; };