diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2022-04-24 09:28:46 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-24 09:28:46 -0300 |
commit | 4b7d306a198d020ce2b6fa1c758c71714bfd036c (patch) | |
tree | 10de79efbbd30107d0f04538c351b0765ec97a06 /ext/http/lib.rs | |
parent | 2eb8c3b82fd54027c35c87ccc94797e34e2e95fd (diff) |
perf(serde_v8): zero-copy StringOrBuffer (#14381)
Diffstat (limited to 'ext/http/lib.rs')
-rw-r--r-- | ext/http/lib.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/ext/http/lib.rs b/ext/http/lib.rs index 7fc90843f..4911c543b 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -38,6 +38,7 @@ use deno_websocket::ws_create_server_stream; use flate2::write::GzEncoder; use flate2::Compression; use fly_accept_encoding::Encoding; +use hyper::body::Bytes; use hyper::server::conn::Http; use hyper::service::Service; use hyper::Body; @@ -612,7 +613,7 @@ async fn op_http_write_headers( // (~4MB) let mut writer = brotli::CompressorWriter::new(Vec::new(), 4096, 6, 22); - writer.write_all(&data.into_bytes())?; + writer.write_all(&data)?; body = builder.body(writer.into_inner().into())?; } _ => { @@ -623,14 +624,14 @@ async fn op_http_write_headers( // 1. // https://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_comp_level let mut writer = GzEncoder::new(Vec::new(), Compression::new(1)); - writer.write_all(&data.into_bytes())?; + writer.write_all(&data)?; body = builder.body(writer.finish()?.into())?; } } } else { // If a buffer was passed, but isn't compressible, we use it to // construct a response body. - body = builder.body(data.into_bytes().into())?; + body = builder.body(Bytes::copy_from_slice(&data).into())?; } new_wr = HttpResponseWriter::Closed; } |