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

refactor: refactor some unnecessary clone and use next_back to make clippy happy #5554

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

yihong0618
Copy link
Contributor

@yihong0618 yihong0618 commented Jan 16, 2025

This patch do not close any issues, just drop some un necessary clone to make a little better performance

and only check the core for now, if it is useful will check all others dir in separate pull request

Which issue does this PR close?

Closes #.

This patch do not close anything

Rationale for this change

no Rationale for this change

What changes are included in this PR?

using static check to understand if we can drop some clone, and found 4 of them,

Are there any user-facing changes?

No

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yihong0618 for polishing this!

core/benches/vs_s3/src/main.rs Show resolved Hide resolved
core/src/raw/http_util/header.rs Show resolved Hide resolved
@@ -157,7 +157,7 @@ pub fn get_basename(path: &str) -> &str {
if !path.ends_with('/') {
return path
.split('/')
.last()
.next_back()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! However, it's a bit harder to understand compared to last(). Would you consider adding a comment to explain it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course will add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would rather go the other way around, warning about last when iterator implements DoubleEndedIterator. The problem with last is that it doesn't require DoubleEndedIterator to be implemented which means that in general case it's going to be slow, and while this can be dealt with manual implementation of that method, most iterators in standard library don't bother to do so. For those that do bother, I don't expect any particular difference between next_back and last even when the iterator is to be immediately dropped.

more: rust-lang/rust-clippy#1822

core/src/services/azblob/error.rs Show resolved Hide resolved
core/src/services/s3/error.rs Outdated Show resolved Hide resolved
Signed-off-by: yihong0618 <[email protected]>
@yihong0618
Copy link
Contributor Author

will change all the body.copy_to_bytes(body.remaining()) in another pull request

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yihong0618 for this!

@Xuanwo Xuanwo merged commit 66bf9db into apache:main Jan 17, 2025
243 checks passed
@yihong0618
Copy link
Contributor Author

will change all the body.copy_to_bytes(body.remaining()) in another pull request

Next maybe I can do this, do I need to open an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants