From 21b88c3ea03ee1bff0105a01a2426fa9965a9f97 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 19 Dec 2019 17:08:38 +0000 Subject: [PATCH] vmm: cpu: Rewrite if chain using match Address updated clippy error: error: `if` chain can be rewritten with `match` --> vmm/src/cpu.rs:668:9 | 668 | / if desired_vcpus > self.present_vcpus() { 669 | | self.activate_vcpus(desired_vcpus, None)?; 670 | | } else if desired_vcpus < self.present_vcpus() { 671 | | self.mark_vcpus_for_removal(desired_vcpus)?; 672 | | } | |_________^ | = note: `-D clippy::comparison-chain` implied by `-D warnings` = help: Consider rewriting the `if` chain to use `cmp` and `match`. = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain Signed-off-by: Rob Bradford --- vmm/src/cpu.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 573e8800b..9e84e749e 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -9,6 +9,7 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause // +use std::cmp; use std::os::unix::thread::JoinHandleExt; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Barrier, Mutex, RwLock, Weak}; @@ -665,13 +666,11 @@ impl CpuManager { } pub fn resize(&mut self, desired_vcpus: u8) -> Result<()> { - if desired_vcpus > self.present_vcpus() { - self.activate_vcpus(desired_vcpus, None)?; - } else if desired_vcpus < self.present_vcpus() { - self.mark_vcpus_for_removal(desired_vcpus)?; + match desired_vcpus.cmp(&self.present_vcpus()) { + cmp::Ordering::Greater => self.activate_vcpus(desired_vcpus, None), + cmp::Ordering::Less => self.mark_vcpus_for_removal(desired_vcpus), + _ => Ok(()), } - - Ok(()) } pub fn shutdown(&mut self) -> Result<()> {