Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(#160): change merged_dictionary to use Lrc and make sync conditional for Parser

Grant Lemonsef33e85bdc36
diff --git a/harper-core/src/parsers/mod.rs b/harper-core/src/parsers/mod.rs
index c1be3796c..6f7493550 100644
--- a/harper-core/src/parsers/mod.rs
+++ b/harper-core/src/parsers/mod.rs
@@ -11,6 +11,13 @@ pub use plain_english::PlainEnglish;
pub use crate::token::{Token, TokenKind, TokenStringExt};
+#[cfg(not(feature = "concurrent"))]
+#[blanket(derive(Box))]
+pub trait Parser {
+ fn parse(&mut self, source: &[char]) -> Vec<Token>;
+}
+
+#[cfg(feature = "concurrent")]
#[blanket(derive(Box))]
pub trait Parser: Send + Sync {
fn parse(&mut self, source: &[char]) -> Vec<Token>;
diff --git a/harper-core/src/spell/merged_dictionary.rs b/harper-core/src/spell/merged_dictionary.rs
index bca70e8fa..12a137d2e 100644
--- a/harper-core/src/spell/merged_dictionary.rs
+++ b/harper-core/src/spell/merged_dictionary.rs
@@ -1,4 +1,4 @@
-use std::sync::Arc;
+use crate::Lrc;
use hashbrown::HashMap;
@@ -12,7 +12,7 @@ pub struct MergedDictionary<T>
where
T: Dictionary + Clone,
{
- children: Vec<Arc<T>>,
+ children: Vec<Lrc<T>>,
merged: HashMap<CharString, WordMetadata>,
}
@@ -27,16 +27,16 @@ where
}
}
- pub fn add_dictionary(&mut self, dictionary: Arc<T>) {
+ pub fn add_dictionary(&mut self, dictionary: Lrc<T>) {
self.children.push(dictionary.clone());
}
}
-impl<T> From<Arc<T>> for MergedDictionary<T>
+impl<T> From<Lrc<T>> for MergedDictionary<T>
where
T: Dictionary + Clone,
{
- fn from(value: Arc<T>) -> Self {
+ fn from(value: Lrc<T>) -> Self {
Self {
children: vec![value],
..Default::default()