Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove memcpy in object store PUT #1039

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions async-nats/src/jetstream/object_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{cmp, str::FromStr, task::Poll, time::Duration};
use crate::{HeaderMap, HeaderValue};
use base64::engine::general_purpose::{STANDARD, URL_SAFE};
use base64::engine::Engine;
use bytes::BytesMut;
use once_cell::sync::Lazy;
use ring::digest::SHA256;
use tokio::io::AsyncReadExt;
Expand Down Expand Up @@ -276,25 +277,24 @@ impl ObjectStore {
let mut object_chunks = 0;
let mut object_size = 0;

let mut buffer = Box::new([0; DEFAULT_CHUNK_SIZE]);
let mut buffer = BytesMut::with_capacity(DEFAULT_CHUNK_SIZE);
let mut context = ring::digest::Context::new(&SHA256);

loop {
let n = data
.read(&mut *buffer)
.read_buf(&mut buffer)
.await
.map_err(|err| PutError::with_source(PutErrorKind::ReadChunks, err))?;

if n == 0 {
break;
}
context.update(&buffer[..n]);

object_size += n;
object_chunks += 1;
let payload = buffer.split().freeze();
context.update(&payload);

// FIXME: this is ugly
let payload = bytes::Bytes::from(buffer[..n].to_vec());
object_size += payload.len();
object_chunks += 1;

self.stream
.context
Expand Down