rsonpath/classification/depth/
shared.rs1#[cfg(target_arch = "x86")]
2pub(super) mod mask_32;
3#[cfg(target_arch = "x86_64")]
4pub(super) mod mask_64;
5#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6pub(super) mod vector_128;
7#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
8pub(super) mod vector_256;
9
10#[allow(unused_macros)]
11macro_rules! depth_classifier {
12 ($name:ident, $core:ident, $vector:ident, $size:literal, $mask_ty:ty) => {
13 pub(crate) struct Constructor;
14
15 impl DepthImpl for Constructor {
16 type Classifier<'i, I, Q>
17 = $name<'i, I, Q>
18 where
19 I: InputBlockIterator<'i, BLOCK_SIZE>,
20 Q: QuoteClassifiedIterator<'i, I, MaskType, BLOCK_SIZE>;
21 }
22
23 pub(crate) struct $name<'i, I, Q> {
24 iter: Q,
25 classifier: $core,
26 were_commas_on: bool,
27 were_colons_on: bool,
28 phantom: PhantomData<(&'i (), I)>,
29 }
30
31 impl<'a, I, Q> FallibleIterator for $name<'a, I, Q>
32 where
33 I: InputBlockIterator<'a, $size>,
34 Q: QuoteClassifiedIterator<'a, I, $mask_ty, $size>,
35 {
36 type Item = $vector<'a, I::Block>;
37 type Error = InputError;
38
39 #[inline(always)]
40 fn next(&mut self) -> Result<Option<Self::Item>, Self::Error> {
41 let quote_classified = self.iter.next()?;
42 Ok(quote_classified.map(|q| new_vector(q, &self.classifier)))
43 }
44 }
45
46 impl<'a, I, Q> DepthIterator<'a, I, Q, $mask_ty, $size> for $name<'a, I, Q>
47 where
48 I: InputBlockIterator<'a, $size>,
49 Q: QuoteClassifiedIterator<'a, I, $mask_ty, $size>,
50 {
51 type Block = $vector<'a, I::Block>;
52
53 #[inline(always)]
54 fn stop(self, block: Option<Self::Block>) -> ResumeClassifierState<'a, I, Q, $mask_ty, $size> {
55 let block_state = block.and_then(|b| {
56 let idx = b.idx;
57 debug!("Depth iterator stopping at index {idx}");
58 if idx >= b.quote_classified.len() {
59 None
60 } else {
61 Some(ResumeClassifierBlockState {
62 block: b.quote_classified,
63 idx,
64 })
65 }
66 });
67
68 ResumeClassifierState {
69 iter: self.iter,
70 block: block_state,
71 are_commas_on: self.were_commas_on,
72 are_colons_on: self.were_colons_on,
73 }
74 }
75
76 #[inline(always)]
77 fn resume(
78 state: ResumeClassifierState<'a, I, Q, $mask_ty, $size>,
79 opening: BracketType,
80 ) -> (Option<Self::Block>, Self) {
81 let classifier = $core::new(opening);
82 let first_block = state.block.and_then(|b| {
83 if b.idx == $size {
84 None
85 } else {
86 Some(new_vector_from(b.block, &classifier, b.idx))
87 }
88 });
89
90 (
91 first_block,
92 $name {
93 iter: state.iter,
94 classifier,
95 phantom: PhantomData,
96 were_commas_on: state.are_commas_on,
97 were_colons_on: state.are_colons_on,
98 },
99 )
100 }
101 }
102 };
103}
104
105#[allow(unused_imports)]
106pub(crate) use depth_classifier;