Skip to content

Commit

Permalink
use a hashset
Browse files Browse the repository at this point in the history
  • Loading branch information
bend-n committed May 16, 2023
1 parent 1c65764 commit b6b9748
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "godot-package-manager"
version = "1.3.1"
version = "1.3.2"
edition = "2021"
authors = ["bendn <[email protected]>"]
description = "A package manager for godot"
Expand Down
23 changes: 1 addition & 22 deletions godot.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
[
{
"name": "@bendn/gdcli",
"tarball": "https://registry.npmjs.org/@bendn/gdcli/-/gdcli-1.2.5.tgz",
"version": "1.2.5"
},
{
"name": "@bendn/splitter",
"tarball": "https://registry.npmjs.org/@bendn/splitter/-/splitter-1.0.6.tgz",
"version": "1.0.6"
},
{
"name": "@bendn/stockfish.gd",
"tarball": "https://registry.npmjs.org/@bendn/stockfish.gd/-/stockfish.gd-1.2.6.tgz",
"version": "1.2.6"
},
{
"name": "@bendn/test",
"tarball": "https://registry.npmjs.org/@bendn/test/-/test-2.0.10.tgz",
"version": "2.0.10"
}
]
[]
10 changes: 6 additions & 4 deletions src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{Context, Result};
use console::style;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::sync::{Arc, Mutex};

pub type Cache = Arc<Mutex<HashMap<String, HashMap<String, Package>>>>;
Expand Down Expand Up @@ -172,9 +172,11 @@ impl ConfigFile {

/// Collect all the packages, and their dependencys.
/// Uses clones, because I wasn't able to get references to work
pub fn collect(&mut self) -> Vec<Package> {
let mut pkgs: Vec<Package> = vec![];
self.for_each(|p| pkgs.push(p.clone()));
pub fn collect(&mut self) -> HashSet<Package> {
let mut pkgs: HashSet<Package> = HashSet::new();
self.for_each(|p| {
pkgs.insert(p.clone());
});
pkgs
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use futures::stream::{self, StreamExt};
use indicatif::{HumanCount, HumanDuration, ProgressBar, ProgressIterator};
use lazy_static::lazy_static;
use reqwest::Client;
use std::collections::HashSet;
use std::fs::{create_dir, read_dir, read_to_string, remove_dir, write};
use std::io::{stdin, Read};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -268,7 +269,7 @@ async fn update(cfg: &mut ConfigFile, modify: bool, v: Verbosity, client: Client
let bar_or_info = v.bar() || v.info();
let (tx, rx) = bar_or_info.then(channel).unzip();
let buf = stream::iter(packages)
.map(|mut p| async {
.map(|mut p| {
let p_name = p.to_string();
let tx = if bar_or_info { tx.clone() } else { None };
let client = client.clone();
Expand All @@ -287,7 +288,6 @@ async fn update(cfg: &mut ConfigFile, modify: bool, v: Verbosity, client: Client
tx.unwrap().send(Status::Finished(p_name.clone())).unwrap();
}
}
.await;
})
.buffer_unordered(PARALLEL);
// use to test the difference in speed
Expand Down Expand Up @@ -354,11 +354,12 @@ fn recursive_delete_empty(dir: String) -> std::io::Result<()> {
}

fn purge(cfg: &mut ConfigFile, v: Verbosity) {
let packages = cfg
.collect()
.into_iter()
.filter(|p| p.is_installed())
.collect::<Vec<Package>>();
let mut packages = HashSet::new();
cfg.for_each(|p| {
if p.is_installed() {
packages.insert(p.clone());
}
});
if packages.is_empty() {
if cfg.packages.is_empty() {
panic!("No packages configured (modify the \"godot.package\" file to add packages)")
Expand Down
2 changes: 1 addition & 1 deletion src/package/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl From<ParsedPackument> for Packument {
fn from(val: ParsedPackument) -> Self {
let mut versions: Vec<ParsedManifest> = val.versions.into_values().collect();
// sort newest first (really badly)
versions.sort_by(|a, b| {
versions.sort_unstable_by(|a, b| {
Version::new(&b.version)
.parse()
.unwrap()
Expand Down

0 comments on commit b6b9748

Please sign in to comment.