mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: cleanup &Arc<dyn T> -> &dyn T
Consuming `&Arc<T>` as argument is almost always an antipattern as it hides whether the callee is going to take over (shared) ownership (by .clone()) or not. Instead, it is better to consume `&dyn T` or `Arc<dyn T>` to be more explicit. This commit cleans up the code. The change is very mechanic and was very easy to implement across the code base. Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
e295719967
commit
7536a95424
@@ -11,7 +11,6 @@
|
||||
//! Implements virtio queues
|
||||
|
||||
use std::fmt::{self, Debug};
|
||||
use std::sync::Arc;
|
||||
|
||||
use virtio_queue::{Queue, QueueT};
|
||||
use vm_memory::GuestAddress;
|
||||
@@ -102,28 +101,28 @@ pub trait AccessPlatform: Send + Sync + Debug {
|
||||
}
|
||||
|
||||
pub trait Translatable {
|
||||
fn translate_gva(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self;
|
||||
fn translate_gpa(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self;
|
||||
fn translate_gva(&self, access_platform: Option<&dyn AccessPlatform>, len: usize) -> Self;
|
||||
fn translate_gpa(&self, access_platform: Option<&dyn AccessPlatform>, len: usize) -> Self;
|
||||
}
|
||||
|
||||
impl Translatable for GuestAddress {
|
||||
fn translate_gva(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self {
|
||||
fn translate_gva(&self, access_platform: Option<&dyn AccessPlatform>, len: usize) -> Self {
|
||||
GuestAddress(self.0.translate_gva(access_platform, len))
|
||||
}
|
||||
fn translate_gpa(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self {
|
||||
fn translate_gpa(&self, access_platform: Option<&dyn AccessPlatform>, len: usize) -> Self {
|
||||
GuestAddress(self.0.translate_gpa(access_platform, len))
|
||||
}
|
||||
}
|
||||
|
||||
impl Translatable for u64 {
|
||||
fn translate_gva(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self {
|
||||
fn translate_gva(&self, access_platform: Option<&dyn AccessPlatform>, len: usize) -> Self {
|
||||
if let Some(access_platform) = access_platform {
|
||||
access_platform.translate_gva(*self, len as u64).unwrap()
|
||||
} else {
|
||||
*self
|
||||
}
|
||||
}
|
||||
fn translate_gpa(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self {
|
||||
fn translate_gpa(&self, access_platform: Option<&dyn AccessPlatform>, len: usize) -> Self {
|
||||
if let Some(access_platform) = access_platform {
|
||||
access_platform.translate_gpa(*self, len as u64).unwrap()
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user