Skip to content

Commit

Permalink
perf: remove useless allocations just for String contains
Browse files Browse the repository at this point in the history
  • Loading branch information
null8626 committed Feb 3, 2024
1 parent 259b55e commit ddf7aa6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl App {
}

pub fn get_cache(&self, ns: &str) -> Option<Cache> {
if self.config.disable_cache.contains(&ns.to_owned()) {
if self.config.disable_cache.iter().any(|s| s.as_str() == ns) {
None
} else {
Cache::get_cache(ns)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/add/modrinth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub async fn run(mut app: App, args: Args) -> Result<()> {
.collect::<Vec<_>>(),
)?;

match if version.loaders.contains(&"datapack".to_owned()) {
match if version.loaders.iter().any(|s| s.as_str() == "datapack") {
if version.loaders.len() > 1 {
app.select(
"Import as...",
Expand Down
3 changes: 2 additions & 1 deletion src/core/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ impl<'a> BuildContext<'a> {
.server
.options
.bootstrap_exts
.contains(&ext.to_string())
.iter()
.any(|s| s.as_str() == ext)
}

pub async fn bootstrap_file(
Expand Down
10 changes: 6 additions & 4 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@ impl<'a> BuildContext<'a> {
let server_jar = self.download_server_jar().await?;
self.app.ci("::endgroup::");

if !self.skip_stages.contains(&"plugins".to_owned()) {
if self.skip_stages.iter().all(|s| s.as_str() != "plugins") {
self.download_addons(AddonType::Plugin).await?;
}

if !self.skip_stages.contains(&"mods".to_owned()) {
if self.skip_stages.iter().all(|s| s.as_str() != "mods") {
self.download_addons(AddonType::Mod).await?;
}

if !self.app.server.worlds.is_empty() && !self.skip_stages.contains(&"worlds".to_owned()) {
if !self.app.server.worlds.is_empty()
&& self.skip_stages.iter().all(|s| s.as_str() != "worlds")
{
self.process_worlds().await?;
}

if self.app.server.path.join("config").exists()
&& !self.skip_stages.contains(&"bootstrap".to_owned())
&& self.skip_stages.iter().any(|s| s.as_str() == "bootstrap")
{
self.bootstrap_files().await?;
}
Expand Down

0 comments on commit ddf7aa6

Please sign in to comment.