Add inplace constructors for QuicheMemSlice and QuicheMemSliceImpl and use them in quic::WriteGfeMemSliceSpanToStream and video_streaming::QuicExternalRequest::WriteBody. This avoids the creation of 3 temporary gfe2::MemSlice objects for every QuicheMemSlice created. PiperOrigin-RevId: 454970726
diff --git a/quiche/common/platform/api/quiche_mem_slice.h b/quiche/common/platform/api/quiche_mem_slice.h index bb703a4..42c3e58 100644 --- a/quiche/common/platform/api/quiche_mem_slice.h +++ b/quiche/common/platform/api/quiche_mem_slice.h
@@ -31,9 +31,13 @@ QuicheMemSlice(std::unique_ptr<char[]> buffer, size_t length) : impl_(std::move(buffer), length) {} - // Constructs QuicheMemSlice from |impl|. It takes the reference away from - // |impl|. - explicit QuicheMemSlice(QuicheMemSliceImpl impl) : impl_(std::move(impl)) {} + // Ensures the use of the in-place constructor (below) is intentional. + struct InPlace {}; + + // Constructs a QuicheMemSlice by constructing |impl_| in-place. + template <typename... Args> + explicit QuicheMemSlice(InPlace, Args&&... args) + : impl_{std::forward<Args>(args)...} {} QuicheMemSlice(const QuicheMemSlice& other) = delete; QuicheMemSlice& operator=(const QuicheMemSlice& other) = delete;