]> git.proxmox.com Git - pve-installer.git/commitdiff
fqdn comparison: make more efficient
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 23 Feb 2024 16:22:18 +0000 (17:22 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 23 Feb 2024 16:29:53 +0000 (17:29 +0100)
Compare lazily to always avoid to vector collections and if one of the
first parts mismatch some lower_case calls.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxmox-installer-common/src/utils.rs

index 8d320759b518d309307ad853c73592fe128456da..36b1d538f3d4888cb224bbfe4b9c5473b06ff6fc 100644 (file)
@@ -258,22 +258,17 @@ impl<'de> Deserialize<'de> for Fqdn {
 }
 
 impl PartialEq for Fqdn {
+    // Case-insensitive comparison, as per RFC 952 "ASSUMPTIONS", RFC 1035 sec. 2.3.3. "Character
+    // Case" and RFC 4343 as a whole
     fn eq(&self, other: &Self) -> bool {
-        // Case-insensitive comparison, as per RFC 952 "ASSUMPTIONS",
-        // RFC 1035 sec. 2.3.3. "Character Case" and RFC 4343 as a whole
-        let a = self
-            .parts
-            .iter()
-            .map(|s| s.to_lowercase())
-            .collect::<Vec<String>>();
+        if self.parts.len() != other.parts.len() {
+            return false;
+        }
 
-        let b = other
-            .parts
+        self.parts
             .iter()
-            .map(|s| s.to_lowercase())
-            .collect::<Vec<String>>();
-
-        a == b
+            .zip(other.parts.iter())
+            .all(|(a, b)| a.to_lowercase() == b.to_lowercase())
     }
 }