@@ -170,7 +170,7 @@ impl TopologyDescription {
170
170
} ;
171
171
172
172
for address in options. hosts . iter ( ) {
173
- let description = ServerDescription :: new ( address. clone ( ) ) ;
173
+ let description = ServerDescription :: new ( address) ;
174
174
self . servers . insert ( address. to_owned ( ) , description) ;
175
175
}
176
176
@@ -387,7 +387,7 @@ impl TopologyDescription {
387
387
let mut new = vec ! [ ] ;
388
388
for host in hosts {
389
389
if !self . servers . contains_key ( & host) {
390
- new. push ( ( host. clone ( ) , ServerDescription :: new ( host) ) ) ;
390
+ new. push ( ( host. clone ( ) , ServerDescription :: new ( & host) ) ) ;
391
391
}
392
392
}
393
393
if let Some ( max) = self . srv_max_hosts {
@@ -599,7 +599,7 @@ impl TopologyDescription {
599
599
return Ok ( ( ) ) ;
600
600
}
601
601
602
- self . add_new_servers ( server_description. known_hosts ( ) ?) ? ;
602
+ self . add_new_servers ( server_description. known_hosts ( ) ?) ;
603
603
604
604
if server_description. invalid_me ( ) ? {
605
605
self . servers . remove ( & server_description. address ) ;
@@ -655,7 +655,7 @@ impl TopologyDescription {
655
655
{
656
656
self . servers . insert (
657
657
server_description. address . clone ( ) ,
658
- ServerDescription :: new ( server_description. address ) ,
658
+ ServerDescription :: new ( & server_description. address ) ,
659
659
) ;
660
660
self . record_primary_state ( ) ;
661
661
return Ok ( ( ) ) ;
@@ -688,16 +688,16 @@ impl TopologyDescription {
688
688
}
689
689
690
690
if let ServerType :: RsPrimary = self . servers . get ( & address) . unwrap ( ) . server_type {
691
- self . servers
692
- . insert ( address. clone ( ) , ServerDescription :: new ( address ) ) ;
691
+ let description = ServerDescription :: new ( & address ) ;
692
+ self . servers . insert ( address, description ) ;
693
693
}
694
694
}
695
695
696
- self . add_new_servers ( server_description. known_hosts ( ) ? ) ?;
697
- let known_hosts : HashSet < _ > = server_description . known_hosts ( ) ? . collect ( ) ;
696
+ let known_hosts = server_description. known_hosts ( ) ?;
697
+ self . add_new_servers ( known_hosts . clone ( ) ) ;
698
698
699
699
for address in addresses {
700
- if !known_hosts. contains ( & address. to_string ( ) ) {
700
+ if !known_hosts. contains ( & address) {
701
701
self . servers . remove ( & address) ;
702
702
}
703
703
}
@@ -724,23 +724,11 @@ impl TopologyDescription {
724
724
}
725
725
726
726
/// Create a new ServerDescription for each address and add it to the topology.
727
- fn add_new_servers < ' a > ( & mut self , servers : impl Iterator < Item = & ' a String > ) -> Result < ( ) > {
728
- let servers: Result < Vec < _ > > = servers. map ( ServerAddress :: parse) . collect ( ) ;
729
-
730
- self . add_new_servers_from_addresses ( servers?. iter ( ) ) ;
731
- Ok ( ( ) )
732
- }
733
-
734
- /// Create a new ServerDescription for each address and add it to the topology.
735
- fn add_new_servers_from_addresses < ' a > (
736
- & mut self ,
737
- servers : impl Iterator < Item = & ' a ServerAddress > ,
738
- ) {
739
- for server in servers {
740
- if !self . servers . contains_key ( server) {
741
- self . servers
742
- . insert ( server. clone ( ) , ServerDescription :: new ( server. clone ( ) ) ) ;
743
- }
727
+ fn add_new_servers ( & mut self , addresses : impl IntoIterator < Item = ServerAddress > ) {
728
+ for address in addresses {
729
+ self . servers
730
+ . entry ( address. clone ( ) )
731
+ . or_insert_with ( || ServerDescription :: new ( & address) ) ;
744
732
}
745
733
}
746
734
}
0 commit comments