Skip to content

Commit

Permalink
refactor: refactor some unnecessary clone and use next_back to make c…
Browse files Browse the repository at this point in the history
…lippy happy

Signed-off-by: yihong0618 <[email protected]>
  • Loading branch information
yihong0618 committed Jan 16, 2025
1 parent ef94a68 commit 10f9db4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions core/benches/vs_s3/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn bench_read(c: &mut Criterion, op: Operator, s3_client: aws_sdk_s3::Client, bu
let mut group = c.benchmark_group("read");
group.throughput(criterion::Throughput::Bytes(16 * 1024 * 1024));

TEST_RUNTIME.block_on(prepare(op.clone()));
TEST_RUNTIME.block_on(prepare(&op));

group.bench_function("opendal_s3_reader", |b| {
b.to_async(&*TEST_RUNTIME).iter(|| async {
Expand Down Expand Up @@ -118,10 +118,10 @@ fn bench_read(c: &mut Criterion, op: Operator, s3_client: aws_sdk_s3::Client, bu
group.finish()
}

async fn prepare(op: Operator) {
async fn prepare(op: &Operator) {
let mut rng = thread_rng();
let mut content = vec![0; 16 * 1024 * 1024];
rng.fill_bytes(&mut content);

op.write("file", content.clone()).await.unwrap();
op.write("file", content).await.unwrap();
}
2 changes: 1 addition & 1 deletion core/src/raw/http_util/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
.with_operation("http_util::parse_header_to_str")
})?;

let value = if let Some(v) = headers.get(name.clone()) {
let value = if let Some(v) = headers.get(&name) {
v
} else {
return Ok(None);
Expand Down
2 changes: 1 addition & 1 deletion core/src/raw/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn get_basename(path: &str) -> &str {
if !path.ends_with('/') {
return path
.split('/')
.last()
.next_back()
.expect("file path without name is invalid");
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/services/azblob/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
_ => (ErrorKind::Unexpected, false),
};

let mut message = match de::from_reader::<_, AzblobError>(bs.clone().reader()) {
let bs_content = bs.chunk();
let mut message = match de::from_reader::<_, AzblobError>(bs_content.reader()) {
Ok(azblob_err) => format!("{azblob_err:?}"),
Err(_) => String::from_utf8_lossy(&bs).into_owned(),
};
Expand Down
5 changes: 3 additions & 2 deletions core/src/services/s3/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
_ => (ErrorKind::Unexpected, false),
};

let (message, s3_err) = de::from_reader::<_, S3Error>(body.clone().reader())
let body_content = body.chunk();
let (message, s3_err) = de::from_reader::<_, S3Error>(body_content.reader())
.map(|s3_err| (format!("{s3_err:?}"), Some(s3_err)))
.unwrap_or_else(|_| (String::from_utf8_lossy(body.chunk()).into_owned(), None));
.unwrap_or_else(|_| (String::from_utf8_lossy(body_content).into_owned(), None));

if let Some(s3_err) = s3_err {
(kind, retryable) = parse_s3_error_code(s3_err.code.as_str()).unwrap_or((kind, retryable));
Expand Down

0 comments on commit 10f9db4

Please sign in to comment.