Skip to content

Commit

Permalink
Optimize parsing with attr.path.is_ident()
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Dec 1, 2022
1 parent d846ccd commit 8fc4d91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
9 changes: 5 additions & 4 deletions pyo3-macros-backend/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ pub fn take_pyo3_options<T: Parse>(attrs: &mut Vec<Attribute>) -> Result<Vec<T>>
}
Ok(false)
};
if let Ok(mut meta) = attr.parse_meta() {
if handle_cfg_feature_pyo3(&mut attr, &mut meta, parse_attr)? {
continue;
if attr.path.is_ident("cfg_attr") {
if let Ok(mut meta) = attr.parse_meta() {
if handle_cfg_feature_pyo3(&mut attr, &mut meta, parse_attr)? {
continue;
}
}
}

if let Some(options) = get_pyo3_options(&attr)? {
out.extend(options.into_iter());
continue;
Expand Down
17 changes: 11 additions & 6 deletions pyo3-macros-backend/src/konst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@ impl ConstAttributes {

for mut attr in attrs.drain(..) {
let parse_attr = |meta, _attr: &Attribute| parse_attribute(&mut attributes, &meta);
if let Ok(mut meta) = attr.parse_meta() {
if handle_cfg_feature_pyo3(&mut attr, &mut meta, parse_attr)? {
continue;
}
if attr.path.is_ident("cfg_attr")
|| attr.path.is_ident("classattr")
|| attr.path.is_ident("pyo3")
{
if let Ok(mut meta) = attr.parse_meta() {
if handle_cfg_feature_pyo3(&mut attr, &mut meta, parse_attr)? {
continue;
}

if parse_attribute(&mut attributes, &meta)? {
continue;
if parse_attribute(&mut attributes, &meta)? {
continue;
}
}
}
new_attrs.push(attr)
Expand Down

0 comments on commit 8fc4d91

Please sign in to comment.