From 852adb0eab0606fc17443eb9ee036a739bfba746 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Sat, 21 Dec 2024 13:54:19 +0100 Subject: [PATCH] fix: some spelling fixes and excludes (#621) * fix: some spelling fixes and excludes * build: removed unused code --- .vscode/settings.json | 39 ++++++++++ src/input.rs | 26 +------ src/lib.rs | 1 - src/pool.rs | 177 ------------------------------------------ 4 files changed, 42 insertions(+), 201 deletions(-) delete mode 100644 src/pool.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 9c391d77..f2fca507 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,4 +6,43 @@ "coverage-gutters.coverageFileNames": [ "lcov.info" ], + "cSpell.ignoreRegExpList": [ + "/\"[^\"]*\\\\u{1b}\\[[^\"]*\"/g", + "/r#\".*\\\\u001b\\[.*\"#/g", + "/\"[^\"]*\\\\x1b\\[[^\"]*\"/g" + ], + "cSpell.words": [ + "AKBNIJGHERHBNMCKJABHSDJ", + "amet", + "ampm", + "april", + "bfnrt", + "bytefmt", + "cdef", + "cpus", + "Deque", + "EVFILT", + "february", + "FFNOP", + "friday", + "ibuf", + "itoa", + "january", + "july", + "june", + "naaaa", + "nbbbb", + "november", + "october", + "orem", + "psum", + "saturday", + "stty", + "thursday", + "tuesday", + "unexp", + "unhex", + "wednesday", + "wyhash" + ] } \ No newline at end of file diff --git a/src/input.rs b/src/input.rs index d63de4fb..ddc24f3e 100644 --- a/src/input.rs +++ b/src/input.rs @@ -19,7 +19,6 @@ use crate::{ error::{Result, HILITE}, index::{Index, Indexer, SourceBlock, SourceMetadata}, iox::ReadFill, - pool::SQPool, replay::{ReplayBufCreator, ReplayBufReader, ReplaySeekReader}, tee::TeeReader, vfs::{FileSystem, LocalFileSystem}, @@ -29,7 +28,6 @@ use crate::{ pub type SequentialStream = Box; pub type RandomAccessStream = Box; -pub type BufPool = SQPool>; // --- @@ -629,26 +627,12 @@ impl> Iterator for Blocks { pub struct Block { input: Arc, index: usize, - buf_pool: Option>, } impl Block { #[inline] pub fn new(input: Arc, index: usize) -> Self { - Self { - input, - index, - buf_pool: None, - } - } - - #[inline] - pub fn with_buf_pool(self, buf_pool: Arc) -> Self { - Self { - input: self.input, - index: self.index, - buf_pool: Some(buf_pool), - } + Self { input, index } } #[inline] @@ -692,11 +676,7 @@ impl BlockLines { pub fn new(mut block: Block) -> Result { let (buf, total) = { let block = &mut block; - let mut buf = if let Some(pool) = &block.buf_pool { - pool.checkout() // TODO: implement checkin - } else { - Vec::new() - }; + let mut buf = Vec::new(); let source_block = block.source_block(); buf.resize(source_block.size.try_into()?, 0); let mut stream = block.input.stream.lock().unwrap(); @@ -707,7 +687,7 @@ impl BlockLines { }; Ok(Self { block, - buf: Arc::new(buf), // TODO: optimize allocations + buf: Arc::new(buf), total, current: 0, byte: 0, diff --git a/src/lib.rs b/src/lib.rs index 7b287f48..e685a94f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,6 @@ mod filtering; mod formatting; mod fsmon; mod model; -mod pool; mod replay; mod scanning; mod serdex; diff --git a/src/pool.rs b/src/pool.rs deleted file mode 100644 index 0a89bc1b..00000000 --- a/src/pool.rs +++ /dev/null @@ -1,177 +0,0 @@ -// third-party imports -use crossbeam_queue::SegQueue; - -// --- - -#[allow(dead_code)] -pub trait Pool: Checkout + Checkin {} - -impl + Checkin> Pool for U {} - -// --- - -#[allow(dead_code)] -pub trait Checkout { - fn checkout(&self) -> T; -} - -// --- - -#[allow(dead_code)] -pub trait Checkin { - fn checkin(&self, item: T); -} - -// --- - -pub trait Factory { - fn new(&self) -> T; -} - -impl Factory for F -where - F: Fn() -> T, -{ - #[inline(always)] - fn new(&self) -> T { - self() - } -} - -// --- - -pub trait Recycler { - fn recycle(&self, item: T) -> T; -} - -impl Recycler for F -where - F: Fn(T) -> T, -{ - #[inline(always)] - fn recycle(&self, item: T) -> T { - self(item) - } -} - -// --- - -pub struct DefaultFactory; - -impl Factory for DefaultFactory { - #[inline(always)] - fn new(&self) -> T { - T::default() - } -} - -// --- - -pub struct RecycleAsIs; - -impl Recycler for RecycleAsIs { - #[inline(always)] - fn recycle(&self, item: T) -> T { - item - } -} - -// --- - -/// Constructs new items of type T using Factory F and recycles them using Recycler R on request. -pub struct SQPool -where - F: Factory, - R: Recycler, -{ - factory: F, - recycler: R, - recycled: SegQueue, -} - -impl SQPool -where - T: Default, -{ - /// Returns a new Pool with default factory. - pub fn new() -> SQPool { - SQPool { - factory: DefaultFactory, - recycler: RecycleAsIs, - recycled: SegQueue::new(), - } - } -} - -impl SQPool -where - F: Factory, -{ - /// Returns a new Pool with the given factory. - pub fn new_with_factory(factory: F) -> SQPool { - SQPool { - factory, - recycler: RecycleAsIs, - recycled: SegQueue::new(), - } - } -} - -impl SQPool -where - F: Factory, - R: Recycler, -{ - /// Converts the Pool to a new Pool with the given factory. - pub fn with_factory>(self, factory: F2) -> SQPool { - SQPool { - factory, - recycler: self.recycler, - recycled: self.recycled, - } - } - - /// Converts the Pool to a new Pool with the given recycle function. - pub fn with_recycler>(self, recycler: R2) -> SQPool { - SQPool { - factory: self.factory, - recycler, - recycled: self.recycled, - } - } - /// Returns a new or recycled T. - #[inline(always)] - pub fn checkout(&self) -> T { - match self.recycled.pop() { - Some(item) => item, - None => self.factory.new(), - } - } - /// Recycles the given T. - #[inline(always)] - pub fn checkin(&self, item: T) { - self.recycled.push(self.recycler.recycle(item)) - } -} - -impl Checkout for SQPool -where - F: Factory, - R: Recycler, -{ - #[inline(always)] - fn checkout(&self) -> T { - self.checkout() - } -} - -impl Checkin for SQPool -where - F: Factory, - R: Recycler, -{ - #[inline(always)] - fn checkin(&self, item: T) { - self.checkin(item) - } -}