Skip to content

Commit

Permalink
Reduce allocations on string.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed Aug 12, 2022
1 parent a470862 commit 3ac02fd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/yew/src/platform/fmt.rs
Expand Up @@ -132,7 +132,10 @@ impl Stream for BufStream {
let mut inner = self.inner.borrow_mut();

if !inner.buf.is_empty() {
return Poll::Ready(Some(inner.buf.split_off(0)));
let mut buf = String::new();
std::mem::swap(&mut buf, &mut inner.buf);

return Poll::Ready(Some(buf));
}

if let BufStreamState::Done = inner.state {
Expand Down Expand Up @@ -189,6 +192,7 @@ where
{
type Item = String;

#[inline]
fn poll_next(
self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
Expand Down

0 comments on commit 3ac02fd

Please sign in to comment.