Skip to content

Commit baeb909

Browse files
Stop using BTreeMap where Vec/HashMap suffices
1 parent 6d93dd5 commit baeb909

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

site/src/load.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
10+
use std::collections::{BTreeSet, HashMap, HashSet};
1111
use std::env;
1212
use std::fs;
1313
use std::path::{Path, PathBuf};
@@ -171,7 +171,7 @@ pub struct InputData {
171171
/// Not all commits are in this map.
172172
pub interpolated: HashMap<String, Vec<Interpolation>>,
173173

174-
pub artifact_data: BTreeMap<String, ArtifactData>,
174+
pub artifact_data: HashMap<String, ArtifactData>,
175175

176176
pub commits: Vec<Commit>,
177177

@@ -192,8 +192,9 @@ impl InputData {
192192
pub fn from_fs(repo_loc: &str) -> anyhow::Result<InputData> {
193193
let repo_loc = PathBuf::from(repo_loc);
194194
let mut skipped = 0;
195-
let mut artifact_data = BTreeMap::new();
196-
let mut data = HashMap::new();
195+
let mut artifact_data = HashMap::new();
196+
let mut data = Vec::new();
197+
let mut commits = HashSet::new();
197198

198199
if !repo_loc.exists() {
199200
// If the repository doesn't yet exist, simplify clone it to the given location.
@@ -275,7 +276,9 @@ impl InputData {
275276
continue;
276277
}
277278

278-
data.insert(contents.commit.clone(), contents);
279+
if commits.insert(contents.commit.clone()) {
280+
data.push(contents);
281+
}
279282
}
280283
}
281284

@@ -292,15 +295,15 @@ impl InputData {
292295
}
293296
};
294297

295-
InputData::new(data.into_iter().collect(), artifact_data, config)
298+
data.sort_unstable_by_key(|d| d.commit.clone());
299+
InputData::new(data, artifact_data, config)
296300
}
297301

298302
pub fn new(
299-
data: BTreeMap<Commit, CommitData>,
300-
artifact_data: BTreeMap<String, ArtifactData>,
303+
data: Vec<CommitData>,
304+
artifact_data: HashMap<String, ArtifactData>,
301305
config: Config,
302306
) -> anyhow::Result<InputData> {
303-
let data = data.into_iter().map(|(_, v)| v).collect::<Vec<_>>();
304307
let mut last_date = None;
305308
let mut stats_list = BTreeSet::new();
306309

0 commit comments

Comments
 (0)