Skip to content

Commit

Permalink
change merged_dictionary to use Lrc and make sync conditional for Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Oct 4, 2024
1 parent 9146953 commit 684c4b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions harper-core/src/parsers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
10 changes: 5 additions & 5 deletions harper-core/src/spell/merged_dictionary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use crate::Lrc;

use hashbrown::HashMap;

Expand All @@ -12,7 +12,7 @@ pub struct MergedDictionary<T>
where
T: Dictionary + Clone,
{
children: Vec<Arc<T>>,
children: Vec<Lrc<T>>,
merged: HashMap<CharString, WordMetadata>,
}

Expand All @@ -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()
Expand Down

0 comments on commit 684c4b0

Please # to comment.