Skip to content

Commit 104236b

Browse files
committed
node: don't allocate vector during hostname resolution
In previous version, we would needlessly allocate vectors while having iterators over SocketAddrs.
1 parent b6b313d commit 104236b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

scylla/src/transport/node.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,13 @@ pub(crate) struct ResolvedContactPoint {
271271
// It prefers to return IPv4s first, and only if there are none, IPv6s.
272272
pub(crate) async fn resolve_hostname(hostname: &str) -> Result<SocketAddr, io::Error> {
273273
let mut ret = None;
274-
let addrs: Vec<SocketAddr> = match lookup_host(hostname).await {
275-
Ok(addrs) => addrs.collect(),
274+
let addrs = match lookup_host(hostname).await {
275+
Ok(addrs) => itertools::Either::Left(addrs),
276276
// Use a default port in case of error, but propagate the original error on failure
277-
Err(e) => lookup_host((hostname, 9042)).await.or(Err(e))?.collect(),
277+
Err(e) => {
278+
let addrs = lookup_host((hostname, 9042)).await.or(Err(e))?;
279+
itertools::Either::Right(addrs)
280+
}
278281
};
279282
for a in addrs {
280283
match a {

0 commit comments

Comments
 (0)