From 81954844158c27de3aa034d1b727d1c13753f325 Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 9 Jun 2024 00:06:24 -0500 Subject: [PATCH] actix-ws: take the encoded buffer when yielding rather than split it (#435) * actix-ws: take the encoded buffer when yielding rather than split it * actix-ws: add memory reduction to changelog --------- Co-authored-by: Rob Ede --- actix-ws/CHANGELOG.md | 1 + actix-ws/src/fut.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/actix-ws/CHANGELOG.md b/actix-ws/CHANGELOG.md index 97e4ccf46..a26894008 100644 --- a/actix-ws/CHANGELOG.md +++ b/actix-ws/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Take the encoded buffer when yielding bytes in the response stream rather than splitting the buffer, reducing memory use - Remove type parameters from `Session::{text, binary}()` methods, replacing with equivalent `impl Trait` parameters. - `Session::text()` now receives an `impl Into`, making broadcasting text messages more efficient. - Allow sending continuations via `Session::continuation()` diff --git a/actix-ws/src/fut.rs b/actix-ws/src/fut.rs index 913cc1d14..786240485 100644 --- a/actix-ws/src/fut.rs +++ b/actix-ws/src/fut.rs @@ -108,7 +108,7 @@ impl Stream for StreamingBody { } if !this.buf.is_empty() { - return Poll::Ready(Some(Ok(this.buf.split().freeze()))); + return Poll::Ready(Some(Ok(std::mem::take(&mut this.buf).freeze()))); } Poll::Pending