chore: add for_loops_forbidden_only parser and switch to fat LTO in release profile

This commit is contained in:
JestDotty
2025-10-04 13:58:40 +00:00
parent 93cf77cb96
commit 8c5938786e
7 changed files with 54 additions and 128 deletions
+13 -13
View File
@@ -54,32 +54,32 @@ static FORBIDDEN_WORDS: LazyLock<Trie> = LazyLock::new(|| {
#[tokio::main]
async fn main() {
let files = env::args().skip(1);
let mut stats = Stats::default();
let mut rx = {
let (tx, rx) = mpsc::unbounded_channel();
for file in files {
//reading files not sequentially average shaves 30ms (of 1250ms), and that's on a NVMe SSD so why not
if let Ok(text) = fs::read_to_string(&file) {
stats.file_count += 1;
let tx = tx.clone();
tokio::spawn(async move {
let mut stats = Stats::default();
let tx = tx.clone();
tokio::spawn(async move {
let mut stats = Stats::default();
//reading files in threads doesn't change speed of any sort but oh well
if let Ok(text) = fs::read_to_string(&file) {
stats.file_count += 1;
parser::for_loops::parse(&mut stats, &text);
let _ = tx.send(stats);
});
} else {
stats.failed_file_count += 1;
}
} else {
stats.failed_file_count += 1;
}
let _ = tx.send(stats);
});
}
rx
};
let mut stats = Stats::default();
while let Some(file_stat) = rx.recv().await {
stats += file_stat;
}
println!("{stats}");
}
/// needs ../books.tar.gz to be extracted
/// needs ../books.tar.gz to be extracted into ../books
#[test]
fn test() {
use std::{env, fs, process::Command, time::Instant};
+4 -6
View File
@@ -11,7 +11,7 @@ pub fn parse(stats: &mut Stats, text: &str) {
{
stats.sentence_count += 1;
for word in sentence
.split_whitespace()
.split_ascii_whitespace()
.map(|s| s.trim())
.filter(|s| !s.is_empty())
{
@@ -21,17 +21,15 @@ pub fn parse(stats: &mut Stats, text: &str) {
for char in word.chars() {
if char.is_numeric() {
stats.numeric_count += 1;
//TODO are numbers capitalized or not? I don't know!
}
if !char.is_ascii_uppercase() {
all_capitalized = false;
} else if !char.is_ascii_uppercase() {
all_capitalized = false;
}
}
if all_capitalized {
stats.capitalized_count += 1;
}
let lowercase_word = word.to_lowercase();
if FORBIDDEN_WORDS.contains(&lowercase_word) {
if FORBIDDEN_WORDS.contains(&word.to_lowercase()) {
stats.forbidden_count += 1;
}
}
@@ -0,0 +1,14 @@
use crate::{FORBIDDEN_WORDS, stats::Stats};
#[allow(dead_code)]
pub fn parse(stats: &mut Stats, text: &str) {
for word in text
.split_ascii_whitespace()
.map(|s| s.trim())
.filter(|s| !s.is_empty())
{
if FORBIDDEN_WORDS.contains(&word.to_lowercase()) {
stats.forbidden_count += 1;
}
}
}
+3 -2
View File
@@ -1,2 +1,3 @@
pub mod muncher;
pub mod for_loops;
pub mod for_loops;
pub mod for_loops_forbidden_only;
pub mod muncher;
+2 -2
View File
@@ -46,12 +46,12 @@ impl Display for Stats {
)?;
writeln!(
f,
"forbidden word percentage: {:.0}%",
"forbidden word percentage: {:.2}%",
(self.forbidden_count as f32 / word_count) * 100.0,
)?;
write!(
f,
"capitalized word percentage: {:.0}%",
"capitalized word percentage: {:.2}%",
(self.capitalized_count as f32 / word_count) * 100.0,
)
}