Merge #216
216: A handful of perf/brevity bits and bobs r=koivunej a=ljedrz Individual commits describe specific changes. Co-authored-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
commit
777a2f2cdf
@ -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 {
|
||||
@ -163,19 +163,10 @@ async fn rm_query<T: IpfsTypes>(
|
||||
hash: cid.to_string(),
|
||||
error: "".to_string(),
|
||||
},
|
||||
Err((cid, e)) => {
|
||||
if force {
|
||||
RmResponse {
|
||||
Err((cid, e)) => RmResponse {
|
||||
hash: cid.to_string(),
|
||||
error: "".to_string(),
|
||||
}
|
||||
} else {
|
||||
RmResponse {
|
||||
hash: cid.to_string(),
|
||||
error: e.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
error: if force { "".to_string() } else { e.to_string() },
|
||||
},
|
||||
})
|
||||
.map(|response: RmResponse| serde_json::to_string(&response))
|
||||
.map(move |result| match result {
|
||||
|
@ -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
|
||||
|
@ -232,7 +232,7 @@ async fn shovel<T: IpfsTypes>(
|
||||
}
|
||||
};
|
||||
|
||||
if tx.send(next.clone()).is_err() {
|
||||
if tx.send(next).is_err() {
|
||||
// currently no more subscribers
|
||||
unsubscribed = false;
|
||||
break;
|
||||
@ -492,7 +492,7 @@ impl<'a> Iterator for QueryAsRawPartsParser<'a> {
|
||||
let mut split2 = self.input.splitn(2, |&b| b == b'&');
|
||||
|
||||
let sequence = split2.next().expect("splitn will always return first");
|
||||
self.input = split2.next().unwrap_or(&[][..]);
|
||||
self.input = split2.next().unwrap_or_default();
|
||||
|
||||
if sequence.is_empty() {
|
||||
continue;
|
||||
@ -500,7 +500,7 @@ impl<'a> Iterator for QueryAsRawPartsParser<'a> {
|
||||
|
||||
let mut split2 = sequence.splitn(2, |&b| b == b'=');
|
||||
let name = split2.next().expect("splitn will always return first");
|
||||
let value = split2.next().unwrap_or(&[][..]);
|
||||
let value = split2.next().unwrap_or_default();
|
||||
// original implementation calls percent_decode for both arguments into lossy Cow<str>
|
||||
return Some((name, value));
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ impl IpfsPath {
|
||||
// FIXME: this would require the iterator to be peekable in addition.
|
||||
return Ok(WalkSuccess::Link(key, cid));
|
||||
}
|
||||
Ipld::Map(mut m) if m.contains_key(&key) => {
|
||||
Ipld::Map(mut m) => {
|
||||
if let Some(ipld) = m.remove(&key) {
|
||||
ipld
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user