diff rust/hg-core/src/config/mod.rs @ 52670:72deeea26bca stable

hg-core: fix usage.resources default logic This makes hg-core use ResourceProfileValue::Medium as the default. Before, it used ResourceProfileValue::Default (now removed), which was not supposed to be a real value, but rather an indirection meaning to use the default (medium). The motivation for this is that my implementation of rhg annotate was slower on some files than Python. This was because Python used the "Medium" profile by default (enabling the revlog chunk cache), while Rust used the "Default" profile (disabling the revlog chunk cache).
author Mitchell Kember <mkember@janestreet.com>
date Tue, 14 Jan 2025 17:15:54 -0500
parents 6499af83735a
children
line wrap: on
line diff
--- a/rust/hg-core/src/config/mod.rs	Tue Jan 14 16:56:22 2025 -0500
+++ b/rust/hg-core/src/config/mod.rs	Tue Jan 14 17:15:54 2025 -0500
@@ -816,20 +816,16 @@
         &self,
         dimension: Option<&str>,
     ) -> ResourceProfile {
-        let mut value =
-            self.resource_profile_from_item(b"usage", b"resources");
-        if let Some(dimension) = &dimension {
-            let sub_value = self.resource_profile_from_item(
+        let value = self.resource_profile_from_item(b"usage", b"resources");
+        let sub_value = dimension.and_then(|dimension| {
+            self.resource_profile_from_item(
                 b"usage",
                 format!("resources.{}", dimension).as_bytes(),
-            );
-            if sub_value != ResourceProfileValue::Default {
-                value = sub_value
-            }
-        }
+            )
+        });
         ResourceProfile {
             dimension: dimension.map(ToOwned::to_owned),
-            value,
+            value: sub_value.or(value).unwrap_or_default(),
         }
     }
 
@@ -837,13 +833,12 @@
         &self,
         section: &[u8],
         item: &[u8],
-    ) -> ResourceProfileValue {
-        match self.get(section, item).unwrap_or(b"default") {
-            b"default" => ResourceProfileValue::Default,
-            b"low" => ResourceProfileValue::Low,
-            b"medium" => ResourceProfileValue::Medium,
-            b"high" => ResourceProfileValue::High,
-            _ => ResourceProfileValue::Default,
+    ) -> Option<ResourceProfileValue> {
+        match self.get(section, item)? {
+            b"low" => Some(ResourceProfileValue::Low),
+            b"medium" => Some(ResourceProfileValue::Medium),
+            b"high" => Some(ResourceProfileValue::High),
+            _ => None,
         }
     }
 }
@@ -857,10 +852,10 @@
     pub value: ResourceProfileValue,
 }
 
-#[derive(Debug, Eq, PartialEq, PartialOrd, Ord)]
+#[derive(Debug, Eq, PartialEq, PartialOrd, Ord, Default)]
 pub enum ResourceProfileValue {
-    Default,
     Low,
+    #[default]
     Medium,
     High,
 }