mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: clippy: add needless_pass_by_value (partially)
This helps to uncover expensive and needless clones in the code base. For example, I prevented extensive clones in the snapshot path where (nested) BTreeMap's have been cloned over and over again. Further, the lint helps devs to much better reason about the ownership of parameters. All of these changes have been done manually with the necessary caution. A few structs that are cheap to clone are now `copy` so that this lint won't trigger for them. I didn't enable the lint so far as it is a massive rabbit hole and needs much more fixes. Nevertheless, it is very useful. 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
0a07c96d17
commit
6a86c157af
@@ -40,14 +40,14 @@ pub struct GsiAllocator {
|
||||
impl GsiAllocator {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
/// New GSI allocator
|
||||
pub fn new(apics: Vec<GsiApic>) -> Self {
|
||||
pub fn new(apics: &[GsiApic]) -> Self {
|
||||
let mut allocator = GsiAllocator {
|
||||
apics: BTreeMap::new(),
|
||||
next_irq: 0xffff_ffff,
|
||||
next_gsi: 0,
|
||||
};
|
||||
|
||||
for apic in &apics {
|
||||
for apic in apics {
|
||||
if apic.base < allocator.next_irq {
|
||||
allocator.next_irq = apic.base;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use crate::page_size::get_page_size;
|
||||
///
|
||||
/// # Example - Use the `SystemAddress` builder.
|
||||
///
|
||||
/// ```
|
||||
/// ```rust
|
||||
/// # #[cfg(target_arch = "x86_64")]
|
||||
/// # use vm_allocator::{GsiApic, SystemAllocator};
|
||||
/// # #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
|
||||
@@ -29,7 +29,7 @@ use crate::page_size::get_page_size;
|
||||
/// GuestAddress(0x1000),
|
||||
/// 0x10000,
|
||||
/// GuestAddress(0x10000000), 0x10000000,
|
||||
/// #[cfg(target_arch = "x86_64")] vec![GsiApic::new(5, 19)]).unwrap();
|
||||
/// #[cfg(target_arch = "x86_64")] &[GsiApic::new(5, 19)]).unwrap();
|
||||
/// #[cfg(target_arch = "x86_64")]
|
||||
/// assert_eq!(allocator.allocate_irq(), Some(5));
|
||||
/// #[cfg(target_arch = "aarch64")]
|
||||
@@ -59,14 +59,14 @@ impl SystemAllocator {
|
||||
/// * `io_size` - (X86) The size of IO memory.
|
||||
/// * `platform_mmio_base` - The starting address of platform MMIO memory.
|
||||
/// * `platform_mmio_size` - The size of platform MMIO memory.
|
||||
/// * `apics` - (X86) Vector of APIC's.
|
||||
/// * `apics` - (X86) slice of APIC's.
|
||||
///
|
||||
pub fn new(
|
||||
io_base: GuestAddress,
|
||||
io_size: GuestUsize,
|
||||
platform_mmio_base: GuestAddress,
|
||||
platform_mmio_size: GuestUsize,
|
||||
#[cfg(target_arch = "x86_64")] apics: Vec<GsiApic>,
|
||||
#[cfg(target_arch = "x86_64")] apics: &[GsiApic],
|
||||
) -> Option<Self> {
|
||||
Some(SystemAllocator {
|
||||
io_address_space: AddressAllocator::new(io_base, io_size)?,
|
||||
|
||||
Reference in New Issue
Block a user