Skip to content

Comments

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

Merged
Xuanwo merged 2 commits intoapache:mainfrom
yihong0618:hy/refactor_some_clone
Jan 17, 2025
Merged

refactor: refactor some unnecessary clone and use next_back to make clippy happy#5554
Xuanwo merged 2 commits intoapache:mainfrom
yihong0618:hy/refactor_some_clone

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

@yihong0618 yihong0618 requested a review from Xuanwo as a code owner January 16, 2025 01:10
@github-actions github-actions bot added the releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor" label Jan 16, 2025
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!

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

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

Labels

releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants