Skip to content

Commit 59cf1f8

Browse files
committed
chore: get rid of unnecessary String allocations
1 parent 92ac580 commit 59cf1f8

File tree

5 files changed

+32
-41
lines changed

5 files changed

+32
-41
lines changed

src/create.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn create_container(
3939
let container = OCIContainer::new(
4040
bundle.to_str().unwrap().to_owned(),
4141
id.to_string(),
42-
pidfile.clone().map_or(
42+
pidfile.as_ref().map_or(
4343
container_dir.to_str().unwrap().to_owned() + "/containerpid",
4444
|x| x.to_str().unwrap().to_string(),
4545
),
@@ -245,8 +245,7 @@ pub fn create_container(
245245
let rootfs_path_str = rootfs_path_abs
246246
.as_os_str()
247247
.to_str()
248-
.expect("Could not convert rootfs-path to string!")
249-
.to_string();
248+
.expect("Could not convert rootfs-path to string!");
250249

251250
debug!(
252251
"Write rootfs-path {} (lenght {}) to init-pipe!",

src/hermit.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,45 +54,42 @@ pub fn get_qemu_args(
5454
"-initrd",
5555
app,
5656
]
57-
.iter()
57+
.into_iter()
5858
.map(|s| s.to_string())
5959
.collect();
6060

6161
if let Some(kvm) = crate::CONFIG.kvm {
6262
if kvm && kvm_support {
63-
exec_args.append(
64-
&mut ["--enable-kvm", "-cpu", "host"]
63+
exec_args.extend(
64+
["--enable-kvm", "-cpu", "host"]
6565
.iter()
66-
.map(|s| s.to_string())
67-
.collect(),
66+
.map(|s| s.to_string()),
6867
);
6968
} else {
70-
exec_args.append(
71-
&mut [
69+
exec_args.extend(
70+
[
7271
"-cpu",
7372
"qemu64,apic,fsgsbase,rdtscp,xsave,xsaveopt,fxsr,rdrand",
7473
]
7574
.iter()
76-
.map(|s| s.to_string())
77-
.collect(),
75+
.map(|s| s.to_string()),
7876
);
7977
}
8078
} else {
8179
// disable kvm support, if the configuration file doesn't enable it
82-
exec_args.append(
83-
&mut [
80+
exec_args.extend(
81+
[
8482
"-cpu",
8583
"qemu64,apic,fsgsbase,rdtscp,xsave,xsaveopt,fxsr,rdrand",
8684
]
8785
.iter()
88-
.map(|s| s.to_string())
89-
.collect(),
86+
.map(|s| s.to_string()),
9087
);
9188
}
9289

9390
if micro_vm {
94-
exec_args.append(
95-
&mut [
91+
exec_args.extend(
92+
[
9693
"-M",
9794
"microvm,x-option-roms=off,pit=off,pic=off,rtc=on,auto-kernel-cmdline=off,acpi=off",
9895
"-global",
@@ -101,12 +98,11 @@ pub fn get_qemu_args(
10198
"-no-user-config",
10299
]
103100
.iter()
104-
.map(|s| s.to_string())
105-
.collect(),
101+
.map(|s| s.to_string()),
106102
);
107103
} else {
108-
exec_args.append(
109-
&mut [
104+
exec_args.extend(
105+
[
110106
"-chardev",
111107
"socket,id=char0,path=/run/vhostqemu",
112108
"-device",
@@ -117,8 +113,7 @@ pub fn get_qemu_args(
117113
"node,memdev=mem",
118114
]
119115
.iter()
120-
.map(|s| s.to_string())
121-
.collect(),
116+
.map(|s| s.to_string()),
122117
);
123118
}
124119

@@ -145,13 +140,15 @@ pub fn get_qemu_args(
145140
args_string
146141
}
147142
NetworkConfig::UserNetwork(user_port) => {
148-
exec_args.push("-netdev".to_string());
149-
exec_args.push(format!(
150-
"user,id=u1,hostfwd=tcp::{user_port}-:{user_port},net=192.168.76.0/24,dhcpstart=192.168.76.9"
151-
));
152-
exec_args.push("-device".to_string());
153-
exec_args.push("virtio-net-pci,netdev=u1,disable-legacy=on".to_string());
154-
exec_args.push("-append".to_string());
143+
exec_args.extend([
144+
"-netdev".to_string(),
145+
format!(
146+
"user,id=u1,hostfwd=tcp::{user_port}-:{user_port},net=192.168.76.0/24,dhcpstart=192.168.76.9"
147+
),
148+
"-device".to_string(),
149+
"virtio-net-pci,netdev=u1,disable-legacy=on".to_string(),
150+
"-append".to_string(),
151+
]);
155152

156153
"".to_string()
157154
}

src/init.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ fn init_stage_child(args: SetupArgs) -> ! {
620620
.expect("RUNH_MICRO_VM was not an unsigned integer!");
621621

622622
if micro_vm == 0 {
623-
let virtiofsd_args: Vec<String> = [
623+
let virtiofsd_args: Vec<&str> = vec![
624624
"virtiofsd",
625625
"--socket-path=/run/vhostqemu",
626626
"--shared-dir",
@@ -630,10 +630,7 @@ fn init_stage_child(args: SetupArgs) -> ! {
630630
"--seccomp",
631631
"none",
632632
"--inode-file-handles=never",
633-
]
634-
.iter()
635-
.map(|s| s.to_string())
636-
.collect();
633+
];
637634

638635
info!("Initialize virtiofsd: {}", virtiofsd_args.join(" "));
639636

src/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn list_containers(project_dir: PathBuf) {
7272
if let Ok(container) = serde_json::from_str::<OCIContainer>(&contents) {
7373
println!(
7474
"{0: <12} {1: <12} {2: <12} {3: <12} {4: <12} {5: <12}",
75-
dir.file_name().into_string().unwrap(),
75+
dir.file_name().to_str().unwrap(),
7676
"",
7777
status,
7878
container.bundle(),

src/mounts.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,14 @@ pub fn configure_mounts(
8282
debug!(
8383
"Mounting {:?} with type {} and options {:?}",
8484
destination_resolved,
85-
mount.typ().as_ref().unwrap_or(&"none".to_string()),
85+
mount.typ().as_deref().unwrap_or("none"),
8686
mount.options().as_ref().unwrap_or(&vec![])
8787
);
8888

8989
let is_bind_mount = mount
9090
.options()
9191
.as_ref()
92-
.map(|options| {
93-
options.contains(&"bind".to_string()) || options.contains(&"rbind".to_string())
94-
})
92+
.map(|options| options.iter().any(|i| i == "bind" || i == "rbind"))
9593
.unwrap_or(false);
9694
if is_bind_mount {
9795
if destination_resolved.parent().map(|i| i == rootfs) == Some(true)

0 commit comments

Comments
 (0)