From 995e1cf80e580b27b655c103d7711abb52a24bed Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 18 Mar 2025 15:26:09 +0000 Subject: [PATCH] Moved input lines on to stack if input is small. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for genmarkov's current commit: Future small blessing − 末小吉 --- Cargo.lock | 10 ++++++++++ Cargo.toml | 2 ++ src/main.rs | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 8b86caa..b769835 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -399,6 +399,7 @@ dependencies = [ "os_pipe", "serde", "serde_cbor", + "smallvec", "tokio", "tokio-uring", "zstd", @@ -630,6 +631,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +dependencies = [ + "serde", +] + [[package]] name = "socket2" version = "0.4.10" diff --git a/Cargo.toml b/Cargo.toml index d611c0d..faa114a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ strip = false default = ["threads"] threads = ["zstd/zstdmt", "dep:num_cpus"] +unstable = ["smallvec/specialization", "smallvec/may_dangle"] #io_uring = ["dep:tokio-uring", "dep:async-compression", "dep:futures", "dep:tokio", "dep:os_pipe"] [dependencies] @@ -35,6 +36,7 @@ num_cpus = { version = "1.16.0", optional = true } os_pipe = { version = "1.2.1", optional = true } serde = { version = "1.0.217", features = ["derive"] } serde_cbor = { version = "0.11.2", features = ["alloc"] } +smallvec = { version = "1.14.0", features = ["union", "const_generics", "const_new", "serde", "write"] } tokio = { version = "1.43.0", features = ["io-util"], optional = true } tokio-uring = { version = "0.5.0", optional = true, features = ["bytes"] } zstd = { version = "0.13.2", features = [] } diff --git a/src/main.rs b/src/main.rs index 7e779a9..de843d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ //#[macro_use] extern crate serde; +use smallvec::SmallVec; use clap::{ Parser, Subcommand, ValueEnum, }; @@ -119,7 +120,7 @@ fn main() { buffered_read_all_lines(&mut stdin, |string| { chain.feed(&string.split_whitespace() .filter(|word| !word.is_empty()) - .map(|s| s.to_owned()).collect::>()); + .map(|s| s.to_owned()).collect::>()); Ok(()) }).expect("Failed to read from stdin");