mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 23:10:30 +00:00
Replace hashbrown with ahash
hashbrown is already used in the standard library, but we want the improved performance of the different hash algorithm. Using ahash directly conveys this intent more clearly.
This commit is contained in:
parent
8df66f7991
commit
dc0ffbe16e
4 changed files with 22 additions and 11 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -9,6 +9,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
|
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
"getrandom",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"version_check",
|
"version_check",
|
||||||
"zerocopy",
|
"zerocopy",
|
||||||
|
@ -246,6 +247,17 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.14.5"
|
version = "0.14.5"
|
||||||
|
@ -517,9 +529,9 @@ dependencies = [
|
||||||
name = "rustlings"
|
name = "rustlings"
|
||||||
version = "6.1.0"
|
version = "6.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
"hashbrown",
|
|
||||||
"notify-debouncer-mini",
|
"notify-debouncer-mini",
|
||||||
"os_pipe",
|
"os_pipe",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
|
|
|
@ -46,9 +46,9 @@ include = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
ahash = "0.8.11"
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
clap = { version = "4.5.13", features = ["derive"] }
|
clap = { version = "4.5.13", features = ["derive"] }
|
||||||
hashbrown = "0.14.5"
|
|
||||||
notify-debouncer-mini = { version = "0.4.1", default-features = false }
|
notify-debouncer-mini = { version = "0.4.1", default-features = false }
|
||||||
os_pipe = "1.2.1"
|
os_pipe = "1.2.1"
|
||||||
ratatui = { version = "0.27.0", default-features = false, features = ["crossterm"] }
|
ratatui = { version = "0.27.0", default-features = false, features = ["crossterm"] }
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use ahash::{HashSet, HashSetExt};
|
||||||
use anyhow::{bail, Context, Error, Result};
|
use anyhow::{bail, Context, Error, Result};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
|
@ -69,7 +70,7 @@ impl AppState {
|
||||||
return StateFileStatus::NotRead;
|
return StateFileStatus::NotRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut done_exercises = hashbrown::HashSet::with_capacity(self.exercises.len());
|
let mut done_exercises = HashSet::with_capacity(self.exercises.len());
|
||||||
|
|
||||||
for done_exerise_name in lines {
|
for done_exerise_name in lines {
|
||||||
if done_exerise_name.is_empty() {
|
if done_exerise_name.is_empty() {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use ahash::{HashSet, HashSetExt};
|
||||||
use anyhow::{anyhow, bail, Context, Error, Result};
|
use anyhow::{anyhow, bail, Context, Error, Result};
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
|
@ -48,9 +49,9 @@ fn check_cargo_toml(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the info of all exercises and return their paths in a set.
|
// Check the info of all exercises and return their paths in a set.
|
||||||
fn check_info_file_exercises(info_file: &InfoFile) -> Result<hashbrown::HashSet<PathBuf>> {
|
fn check_info_file_exercises(info_file: &InfoFile) -> Result<HashSet<PathBuf>> {
|
||||||
let mut names = hashbrown::HashSet::with_capacity(info_file.exercises.len());
|
let mut names = HashSet::with_capacity(info_file.exercises.len());
|
||||||
let mut paths = hashbrown::HashSet::with_capacity(info_file.exercises.len());
|
let mut paths = HashSet::with_capacity(info_file.exercises.len());
|
||||||
|
|
||||||
let mut file_buf = String::with_capacity(1 << 14);
|
let mut file_buf = String::with_capacity(1 << 14);
|
||||||
for exercise_info in &info_file.exercises {
|
for exercise_info in &info_file.exercises {
|
||||||
|
@ -111,10 +112,7 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<hashbrown::HashSet<
|
||||||
// Check `dir` for unexpected files.
|
// Check `dir` for unexpected files.
|
||||||
// Only Rust files in `allowed_rust_files` and `README.md` files are allowed.
|
// Only Rust files in `allowed_rust_files` and `README.md` files are allowed.
|
||||||
// Only one level of directory nesting is allowed.
|
// Only one level of directory nesting is allowed.
|
||||||
fn check_unexpected_files(
|
fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet<PathBuf>) -> Result<()> {
|
||||||
dir: &str,
|
|
||||||
allowed_rust_files: &hashbrown::HashSet<PathBuf>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let unexpected_file = |path: &Path| {
|
let unexpected_file = |path: &Path| {
|
||||||
anyhow!("Found the file `{}`. Only `README.md` and Rust files related to an exercise in `info.toml` are allowed in the `{dir}` directory", path.display())
|
anyhow!("Found the file `{}`. Only `README.md` and Rust files related to an exercise in `info.toml` are allowed in the `{dir}` directory", path.display())
|
||||||
};
|
};
|
||||||
|
@ -253,7 +251,7 @@ fn check_solutions(
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut sol_paths = hashbrown::HashSet::with_capacity(info_file.exercises.len());
|
let mut sol_paths = HashSet::with_capacity(info_file.exercises.len());
|
||||||
let mut fmt_cmd = Command::new("rustfmt");
|
let mut fmt_cmd = Command::new("rustfmt");
|
||||||
fmt_cmd
|
fmt_cmd
|
||||||
.arg("--check")
|
.arg("--check")
|
||||||
|
|
Loading…
Reference in a new issue