From 00f3a6de12b6a2e20694cd0557d93e02d4de4b3f Mon Sep 17 00:00:00 2001 From: Ji-Xinyou Date: Mon, 15 Aug 2022 11:14:18 +0800 Subject: [PATCH] runtime-rs: make static resource mgmt idiomatic Make the get value process (cpu and mem) more idiomatic. Fixes: #4742 Signed-off-by: Ji-Xinyou --- src/libs/kata-types/src/annotations/mod.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/libs/kata-types/src/annotations/mod.rs b/src/libs/kata-types/src/annotations/mod.rs index 4ae67a9f06..07cdbe1a1d 100644 --- a/src/libs/kata-types/src/annotations/mod.rs +++ b/src/libs/kata-types/src/annotations/mod.rs @@ -383,10 +383,7 @@ impl Annotation { let value = self .get_value::(SANDBOX_CPU_QUOTA_KEY) .unwrap_or(Some(0)); - if let Some(q) = value { - return q; - } - 0 + value.unwrap_or(0) } /// Get the annotation of cpu period for sandbox @@ -394,19 +391,13 @@ impl Annotation { let value = self .get_value::(SANDBOX_CPU_PERIOD_KEY) .unwrap_or(Some(0)); - if let Some(p) = value { - return p; - } - 0 + value.unwrap_or(0) } /// Get the annotation of memory for sandbox pub fn get_sandbox_mem(&self) -> i64 { let value = self.get_value::(SANDBOX_MEM_KEY).unwrap_or(Some(0)); - if let Some(m) = value { - return m; - } - 0 + value.unwrap_or(0) } /// Get the annotation to specify the Resources.Memory.Swappiness.