Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse_db_options: avoid string copy for integer options #984

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions nexus/analyzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,16 +676,14 @@ fn parse_db_options(
// partition_count default to 3 if not set, parse as int
let partition_count = opts
.get("partition_count")
.map(|s| s.to_string())
.unwrap_or_else(|| "3".to_string())
.unwrap_or(&"3")
.parse::<u32>()
.context("unable to parse partition_count as valid int")?;

// message_retention_in_days default to 7 if not set, parse as int
let message_retention_in_days = opts
.get("message_retention_in_days")
.map(|s| s.to_string())
.unwrap_or_else(|| "7".to_string())
.unwrap_or(&"7")
.parse::<u32>()
.context("unable to parse message_retention_in_days as valid int")?;

Expand Down
14 changes: 7 additions & 7 deletions nexus/analyzer/src/qrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ pub fn process_options(
anyhow::bail!("{} must be one of {:?}", name, values);
}
}
opts.insert((*name).to_string(), Value::String(str.clone()));
opts.insert(name.to_string(), Value::String(str.clone()));
} else {
anyhow::bail!("Invalid value for {}", name);
}
} else if *required {
anyhow::bail!("{} is required", name);
} else if let Some(default) = default_val {
opts.insert((*name).to_string(), Value::String(default.to_string()));
opts.insert(name.to_string(), Value::String(default.to_string()));
}
}
QRepOptionType::Int {
Expand All @@ -139,15 +139,15 @@ pub fn process_options(
anyhow::bail!("{} must be greater than {}", name, min);
}
}
opts.insert((*name).to_string(), Value::Number(num.into()));
opts.insert(name.to_string(), Value::Number(num.into()));
} else {
anyhow::bail!("Invalid value for {}", name);
}
} else if *required {
anyhow::bail!("{} is required", name);
} else {
let v = *default_value;
opts.insert((*name).to_string(), Value::Number(v.into()));
opts.insert(name.to_string(), Value::Number(v.into()));
}
}
QRepOptionType::StringArray { name } => {
Expand All @@ -158,7 +158,7 @@ pub fn process_options(
.split(',')
.map(|s| Value::String(s.trim().to_string()))
.collect();
opts.insert((*name).to_string(), Value::Array(values));
opts.insert(name.to_string(), Value::Array(values));
} else {
anyhow::bail!("Invalid value for {}", name);
}
Expand All @@ -171,15 +171,15 @@ pub fn process_options(
} => {
if let Some(raw_value) = raw_opts.remove(*name) {
if let SqlValue::Boolean(b) = raw_value {
opts.insert((*name).to_string(), Value::Bool(*b));
opts.insert(name.to_string(), Value::Bool(*b));
} else {
anyhow::bail!("Invalid value for {}", name);
}
} else if *required {
anyhow::bail!("{} is required", name);
} else {
let v = *default_value;
opts.insert((*name).to_string(), Value::Bool(v));
opts.insert(name.to_string(), Value::Bool(v));
}
}
}
Expand Down
Loading