Skip to content

Conversation

@bellau
Copy link
Contributor

@bellau bellau commented Feb 14, 2022

It's a micro optimization. I don't know if it's really necessary (less alloc is always better).

}

fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &MetaTemplate) {
fn collect_vars<F: FnMut(SmolStr)>(collector_fun: &mut F, pattern: &MetaTemplate) {
Copy link
Member

@Veykril Veykril Feb 14, 2022

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+

Copy link
Contributor Author

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

Copy link
Member

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

@bors
Copy link
Contributor

bors bot commented Feb 14, 2022

✌️ bellau can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

}

fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &MetaTemplate) {
fn collect_vars<F: FnMut(SmolStr)>(collector_fun: &mut F, pattern: &MetaTemplate) {
Copy link
Contributor Author

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)

Copy link
Member

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

@bellau bellau force-pushed the impr-remove-unecessary-temp-buffer branch from b790cf7 to ff4024e Compare February 15, 2022 09:21
@bellau
Copy link
Contributor Author

bellau commented Feb 15, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 15, 2022

@bors bors bot merged commit f0210f8 into rust-lang:master Feb 15, 2022
@lnicola lnicola changed the title Impr mbe: remove unecessary temporary vec internal: Avoid temporary Vec in MBE Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants