瀏覽代碼

Factor out handle lookups in the namespace

Isaac Woods 4 年之前
父節點
當前提交
4f81b71503
共有 1 個文件被更改,包括 7 次插入4 次删除
  1. 7 4
      aml/src/namespace.rs

+ 7 - 4
aml/src/namespace.rs

@@ -161,15 +161,18 @@ impl Namespace {
         Ok(self.object_map.get_mut(&handle).unwrap())
     }
 
-    pub fn get_by_path(&self, path: &AmlName) -> Result<&AmlValue, AmlError> {
+    pub fn get_handle(&self, path: &AmlName) -> Result<AmlHandle, AmlError> {
         let (level, last_seg) = self.get_level_for_path(path)?;
-        let &handle = level.values.get(&last_seg).ok_or(AmlError::ValueDoesNotExist(path.clone()))?;
+        Ok(*level.values.get(&last_seg).ok_or(AmlError::ValueDoesNotExist(path.clone()))?)
+    }
+
+    pub fn get_by_path(&self, path: &AmlName) -> Result<&AmlValue, AmlError> {
+        let handle = self.get_handle(path)?;
         Ok(self.get(handle).unwrap())
     }
 
     pub fn get_by_path_mut(&mut self, path: &AmlName) -> Result<&mut AmlValue, AmlError> {
-        let (level, last_seg) = self.get_level_for_path(path)?;
-        let &handle = level.values.get(&last_seg).ok_or(AmlError::ValueDoesNotExist(path.clone()))?;
+        let handle = self.get_handle(path)?;
         Ok(self.get_mut(handle).unwrap())
     }