Replace magic number with DEFAULT_MAX_DISCS

This commit is contained in:
2Shirt 2025-04-20 23:36:34 -07:00
parent d0eecc36c5
commit f556703baf
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -149,13 +149,12 @@ pub fn build_dest_format_script(disk_id: usize, part_type: &PartitionTableType)
#[must_use]
pub fn build_get_disk_script(disk_nums: Option<Vec<&str>>) -> String {
let capacity = DEFAULT_MAX_DISKS * 3 + 1;
let script: String;
// Get disk and partition details
if let Some(disks) = disk_nums {
// (Slower case)
let mut script_parts = Vec::with_capacity(capacity);
let mut script_parts = Vec::with_capacity(DEFAULT_MAX_DISKS * 3 + 1);
// Get list of disks
script_parts.push(String::from("list disk"));
@ -171,7 +170,7 @@ pub fn build_get_disk_script(disk_nums: Option<Vec<&str>>) -> String {
script = script_parts.join("\n");
} else {
// (Best case)
let mut script_parts = Vec::with_capacity(capacity);
let mut script_parts = Vec::with_capacity(DEFAULT_MAX_DISKS + 1);
// Get list of disks
script_parts.push("list disk");
@ -181,9 +180,9 @@ pub fn build_get_disk_script(disk_nums: Option<Vec<&str>>) -> String {
script_parts.push("detail disk");
script_parts.push("list partition");
// Limit to 8 disks (if there's more the manual "worst" case will be used)
// Limit to DEFAULT_MAX_DISKS (if there's more the manual "worst" case will be used)
let mut i = 0;
while i < 8 {
while i < DEFAULT_MAX_DISKS {
script_parts.push("select disk next");
script_parts.push("detail disk");
script_parts.push("list partition");