-
Notifications
You must be signed in to change notification settings - Fork 1.9k
internal: Avoid temporary Vec in MBE
#11475
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
internal: Avoid temporary Vec in MBE
#11475
Conversation
crates/mbe/src/expander/matcher.rs
Outdated
| } | ||
|
|
||
| fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &MetaTemplate) { | ||
| fn collect_vars<F: FnMut(SmolStr)>(collector_fun: &mut F, pattern: &MetaTemplate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to pass the closure by mut ref here if I see that right
bors d+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustc seems to disagree or maybe I miss something. I need a mut ref because the closure's call need a &mut self
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mut collector_fun: F should work
Calling the closure requires &mut F, if you pass ownership the name needs to be mutable for rust to be able to borrow mutably when calling it
|
✌️ bellau can now approve this pull request. To approve and merge a pull request, simply reply with |
crates/mbe/src/expander/matcher.rs
Outdated
| } | ||
|
|
||
| fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &MetaTemplate) { | ||
| fn collect_vars<F: FnMut(SmolStr)>(collector_fun: &mut F, pattern: &MetaTemplate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it better to use this notation ?
fn collect_vars(collector_fun: &mut impl FnMut(SmolStr), pattern: &MetaTemplate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either works, we don't really have any style guidelines on this I think. I personally would probably prefer the impl notation here
b790cf7 to
ff4024e
Compare
|
bors r+ |
Vec in MBE
It's a micro optimization. I don't know if it's really necessary (less alloc is always better).