Merge branch 'cargo_bench'
This commit is contained in:
commit
ed105b04ad
@ -2,8 +2,11 @@
|
|||||||
#![feature(trait_alias)]
|
#![feature(trait_alias)]
|
||||||
#![feature(path_file_prefix)]
|
#![feature(path_file_prefix)]
|
||||||
#![feature(is_sorted)]
|
#![feature(is_sorted)]
|
||||||
|
#![feature(test)]
|
||||||
// TODO: #![warn(missing_docs)]
|
// TODO: #![warn(missing_docs)]
|
||||||
|
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
#[cfg(feature = "compare")]
|
#[cfg(feature = "compare")]
|
||||||
pub mod compare;
|
pub mod compare;
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ use crate::context::RefContext;
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
use crate::error::MyError;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
|
use crate::parser::macros::element;
|
||||||
use crate::parser::util::start_of_line;
|
use crate::parser::util::start_of_line;
|
||||||
use crate::types::AffiliatedKeywords;
|
use crate::types::AffiliatedKeywords;
|
||||||
use crate::types::Keyword;
|
use crate::types::Keyword;
|
||||||
@ -151,11 +152,12 @@ fn affiliated_key<'b, 'g, 'r, 's>(
|
|||||||
context: RefContext<'b, 'g, 'r, 's>,
|
context: RefContext<'b, 'g, 'r, 's>,
|
||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
alt((
|
element!(dual_affiliated_key, context, input);
|
||||||
parser_with_context!(dual_affiliated_key)(context),
|
element!(plain_affiliated_key, context, input);
|
||||||
parser_with_context!(plain_affiliated_key)(context),
|
element!(export_keyword, input);
|
||||||
export_keyword,
|
Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||||
))(input)
|
"No affiliated key.",
|
||||||
|
))))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
@ -250,3 +252,25 @@ fn export_keyword<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
|
|||||||
take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)),
|
take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)),
|
||||||
)))(input)
|
)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use test::Bencher;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::context::Context;
|
||||||
|
use crate::context::ContextElement;
|
||||||
|
use crate::context::GlobalSettings;
|
||||||
|
use crate::context::List;
|
||||||
|
use crate::parser::OrgSource;
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_affiliated_keyword(b: &mut Bencher) {
|
||||||
|
let input = OrgSource::new("#+CAPTION[*foo*]: bar *baz*");
|
||||||
|
let global_settings = GlobalSettings::default();
|
||||||
|
let initial_context = ContextElement::document_context();
|
||||||
|
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
||||||
|
|
||||||
|
b.iter(|| assert!(affiliated_keyword(&initial_context, input).is_ok()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,6 +35,11 @@ macro_rules! element {
|
|||||||
return Ok((remaining, ele));
|
return Ok((remaining, ele));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
($parser:expr, $input: expr) => {
|
||||||
|
if let Ok((remaining, ele)) = $parser($input) {
|
||||||
|
return Ok((remaining, ele));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use element;
|
pub(crate) use element;
|
||||||
|
Loading…
Reference in New Issue
Block a user