No performance change switching affiliated_key to using element macro.

This commit is contained in:
Tom Alexander 2023-10-16 15:57:18 -04:00
parent 72b4cf8e71
commit f10efec21d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 12 additions and 5 deletions

View File

@ -27,6 +27,7 @@ use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::MyError;
use crate::error::Res;
use crate::parser::macros::element;
use crate::parser::util::start_of_line;
use crate::types::AffiliatedKeywords;
use crate::types::Keyword;
@ -151,11 +152,12 @@ fn affiliated_key<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
alt((
parser_with_context!(dual_affiliated_key)(context),
parser_with_context!(plain_affiliated_key)(context),
export_keyword,
))(input)
element!(dual_affiliated_key, context, input);
element!(plain_affiliated_key, context, input);
element!(export_keyword, input);
Err(nom::Err::Error(CustomError::MyError(MyError(
"No affiliated key.",
))))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]

View File

@ -35,6 +35,11 @@ macro_rules! element {
return Ok((remaining, ele));
}
};
($parser:expr, $input: expr) => {
if let Ok((remaining, ele)) = $parser($input) {
return Ok((remaining, ele));
}
};
}
pub(crate) use element;