@@ -170,7 +170,7 @@ impl TopologyDescription {
170170 } ;
171171
172172 for address in options. hosts . iter ( ) {
173- let description = ServerDescription :: new ( address. clone ( ) ) ;
173+ let description = ServerDescription :: new ( address) ;
174174 self . servers . insert ( address. to_owned ( ) , description) ;
175175 }
176176
@@ -387,7 +387,7 @@ impl TopologyDescription {
387387 let mut new = vec ! [ ] ;
388388 for host in hosts {
389389 if !self . servers . contains_key ( & host) {
390- new. push ( ( host. clone ( ) , ServerDescription :: new ( host) ) ) ;
390+ new. push ( ( host. clone ( ) , ServerDescription :: new ( & host) ) ) ;
391391 }
392392 }
393393 if let Some ( max) = self . srv_max_hosts {
@@ -599,7 +599,7 @@ impl TopologyDescription {
599599 return Ok ( ( ) ) ;
600600 }
601601
602- self . add_new_servers ( server_description. known_hosts ( ) ?) ? ;
602+ self . add_new_servers ( server_description. known_hosts ( ) ?) ;
603603
604604 if server_description. invalid_me ( ) ? {
605605 self . servers . remove ( & server_description. address ) ;
@@ -655,7 +655,7 @@ impl TopologyDescription {
655655 {
656656 self . servers . insert (
657657 server_description. address . clone ( ) ,
658- ServerDescription :: new ( server_description. address ) ,
658+ ServerDescription :: new ( & server_description. address ) ,
659659 ) ;
660660 self . record_primary_state ( ) ;
661661 return Ok ( ( ) ) ;
@@ -688,16 +688,16 @@ impl TopologyDescription {
688688 }
689689
690690 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 ) ;
693693 }
694694 }
695695
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 ( ) ) ;
698698
699699 for address in addresses {
700- if !known_hosts. contains ( & address. to_string ( ) ) {
700+ if !known_hosts. contains ( & address) {
701701 self . servers . remove ( & address) ;
702702 }
703703 }
@@ -724,23 +724,11 @@ impl TopologyDescription {
724724 }
725725
726726 /// 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) ) ;
744732 }
745733 }
746734}
0 commit comments