Skip to content

Commit

Permalink
TokenWithStrategy::new() optimisation + style enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
wprzytula authored and havaker committed Jan 22, 2023
1 parent f356b0e commit 81eea08
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions scylla/src/transport/load_balancing/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,10 @@ struct TokenWithStrategy<'a> {

impl<'a> TokenWithStrategy<'a> {
fn new(query: &'a QueryInfo, cluster: &'a ClusterData) -> Option<TokenWithStrategy<'a>> {
let keyspace = query
.keyspace
.and_then(|keyspace| cluster.get_keyspace_info().get(keyspace));
let strategy = keyspace.map(|keyspace| &keyspace.strategy);

if let (Some(token), Some(strategy)) = (query.token, strategy) {
return Some(TokenWithStrategy { strategy, token });
}

None
let token = query.token?;
let keyspace_name = query.keyspace?;
let keyspace = cluster.get_keyspace_info().get(keyspace_name)?;
let strategy = &keyspace.strategy;
Some(TokenWithStrategy { strategy, token })
}
}

0 comments on commit 81eea08

Please sign in to comment.