1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

perf: remove rand dependency

This commit is contained in:
Kevin Amado 2022-02-23 11:40:19 -05:00
parent 20fae077d9
commit 0f38838292
5 changed files with 8 additions and 136 deletions

54
Cargo.lock generated
View file

@ -21,7 +21,6 @@ name = "alejandra_engine"
version = "0.4.0"
dependencies = [
"clap",
"rand",
"rnix",
"rowan",
]
@ -142,17 +141,6 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "getrandom"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
@ -254,42 +242,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "ppv-lite86"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
"getrandom",
]
[[package]]
name = "rayon"
version = "1.5.1"
@ -474,12 +426,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "winapi"
version = "0.3.9"

66
front/Cargo.lock generated
View file

@ -7,7 +7,6 @@ name = "alejandra_engine"
version = "0.4.0"
dependencies = [
"clap",
"rand",
"rnix",
"rowan",
]
@ -18,7 +17,6 @@ version = "0.4.0"
dependencies = [
"alejandra_engine",
"console_error_panic_hook",
"getrandom",
"wasm-bindgen",
"wee_alloc",
]
@ -105,19 +103,6 @@ version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "328b822bdcba4d4e402be8d9adb6eebf269f969f8eadef977a553ff3c4fbcb58"
[[package]]
name = "getrandom"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
"libc",
"wasi",
"wasm-bindgen",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
@ -149,15 +134,6 @@ dependencies = [
"hashbrown 0.11.2",
]
[[package]]
name = "js-sys"
version = "0.3.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -218,12 +194,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "ppv-lite86"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "proc-macro2"
version = "1.0.36"
@ -242,36 +212,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
"getrandom",
]
[[package]]
name = "rnix"
version = "0.10.1"
@ -361,12 +301,6 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm-bindgen"
version = "0.2.79"

View file

@ -1,7 +1,6 @@
[dependencies]
alejandra_engine = { "path" = "../src/alejandra_engine" }
console_error_panic_hook = "*"
getrandom = { version = "*", features = ["js"] }
wasm-bindgen = "*"
wee_alloc = "*"

View file

@ -1,6 +1,5 @@
[dependencies]
clap = { version = "*", features = ["cargo"] }
rand = "*"
rnix = "*"
rowan = "0.12.6" # follows rnix

View file

@ -1,3 +1,9 @@
const PLACEHOLDER: &str = "\
4d13159079d76c1398db5f3ab0c62325\
f884b545e63226f7ec8aad96c52e13e8\
6b219abc9462c41b87e47344752e9940\
abf9353565f69a5db5c672b89372b84c";
pub fn rule(
build_ctx: &crate::builder::BuildCtx,
node: &rnix::SyntaxNode,
@ -26,8 +32,6 @@ pub fn rule(
}
}
} else {
let placeholder = get_placeholder();
let elements: Vec<rnix::SyntaxElement> = children
.get_remaining()
.iter()
@ -45,7 +49,7 @@ pub fn rule(
let token = element.clone().into_token().unwrap();
token.text().to_string()
}
_ => placeholder.to_string(),
_ => PLACEHOLDER.to_string(),
})
.collect();
@ -111,7 +115,7 @@ pub fn rule(
for (index, line) in lines.iter().enumerate() {
let portions: Vec<String> = line
.split(&placeholder)
.split(PLACEHOLDER)
.map(|portion| portion.to_string())
.collect();
@ -159,13 +163,3 @@ pub fn rule(
steps
}
fn get_placeholder() -> String {
use rand::RngCore;
let mut bytes = [0u8; 32];
rand::thread_rng().fill_bytes(&mut bytes);
bytes.iter().map(|byte| format!("{:02X}", byte)).collect()
}