-
Notifications
You must be signed in to change notification settings - Fork 108
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
node: tiny optimizations and code refactors #1108
node: tiny optimizations and code refactors #1108
Conversation
We can consume the `to_resolve` vector and move the datacenter string, instead of cloning.
In previous version, we would needlessly allocate vectors while having iterators over SocketAddrs.
Notice that using `find_or_last` is equivalent to previous version.
This is just a negation of `is_empty()` method. For reference: ``` fn is_empty(&self) -> bool { self.conns.iter().all(|conns| conns.is_empty()) } ```
|
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.
Thanks for including is_empty
body in commit message - it makes review easier.
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.
I love this! Both allocation optimisations and adjusting to functional paradigm.
addrs | ||
.find_or_last(|addr| matches!(addr, SocketAddr::V4(_))) | ||
.ok_or_else(|| { | ||
io::Error::new( | ||
io::ErrorKind::Other, | ||
format!("Empty address list returned by DNS for {}", hostname), | ||
) | ||
}) |
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.
Any ideas BTW why we're biased for IPv4 addresses???
While reading, and trying to understand the hostname resolution and pool refiller logic, I found some places where things could be slightly adjusted. These changes are mostly tiny optimizations and things that aid code readability.
Pre-review checklist
./docs/source/
.Fixes:
annotations to PR description.