perf: faster Bytes conversions in http::{block, dag}

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-06-29 13:35:38 +02:00
parent 1c299109d2
commit a57d49216a
2 changed files with 4 additions and 4 deletions

View File

@ -75,7 +75,7 @@ async fn put_query<T: IpfsTypes>(
1 => Version::V1,
_ => return Err(StringError::from("invalid cid version").into()),
};
let mut buf = form
let buf = form
.next()
.await
.ok_or(InvalidMultipartFormData)?
@ -84,7 +84,7 @@ async fn put_query<T: IpfsTypes>(
.await
.ok_or(InvalidMultipartFormData)?
.map_err(|_| InvalidMultipartFormData)?;
let data = buf.to_bytes().as_ref().to_vec().into_boxed_slice();
let data = Box::from(buf.bytes());
let digest = hasher(&data);
let cid = Cid::new(version, format, digest).map_err(StringError::from)?;
let response = PutResponse {

View File

@ -32,7 +32,7 @@ async fn put_query<T: IpfsTypes>(
"sha3-512" => (Sha3_512::digest as fn(&[u8]) -> Multihash, false),
_ => return Err(StringError::from("unknown hash").into()),
};
let mut buf = form
let buf = form
.next()
.await
.ok_or(InvalidMultipartFormData)?
@ -41,7 +41,7 @@ async fn put_query<T: IpfsTypes>(
.await
.ok_or(InvalidMultipartFormData)?
.map_err(|_| InvalidMultipartFormData)?;
let data = buf.to_bytes().as_ref().to_vec().into_boxed_slice();
let data = Box::from(buf.bytes());
let digest = hasher(&data);
let cid = if v0_fmt && v0_hash {
// this is quite ugly way but apparently js-ipfs generates a v0 cid for this combination