Skip to content

Commit 25fe971

Browse files
committed
Optimize parsing with attr.path.is_ident()
1 parent e21fb3f commit 25fe971

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pyo3-macros-backend/src/attributes.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,13 @@ pub fn take_pyo3_options<T: Parse>(attrs: &mut Vec<Attribute>) -> Result<Vec<T>>
195195
}
196196
Ok(false)
197197
};
198-
if let Ok(mut meta) = attr.parse_meta() {
199-
if handle_cfg_feature_pyo3(&mut attr, &mut meta, parse_attr)? {
200-
continue;
198+
if attr.path.is_ident("cfg_attr") {
199+
if let Ok(mut meta) = attr.parse_meta() {
200+
if handle_cfg_feature_pyo3(&mut attr, &mut meta, parse_attr)? {
201+
continue;
202+
}
201203
}
202204
}
203-
204205
if let Some(options) = get_pyo3_options(&attr)? {
205206
out.extend(options.into_iter());
206207
continue;

pyo3-macros-backend/src/konst.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ impl ConstAttributes {
7070

7171
for mut attr in attrs.drain(..) {
7272
let parse_attr = |meta, _attr: &Attribute| parse_attribute(&mut attributes, &meta);
73-
if let Ok(mut meta) = attr.parse_meta() {
74-
if handle_cfg_feature_pyo3(&mut attr, &mut meta, parse_attr)? {
75-
continue;
76-
}
73+
if attr.path.is_ident("cfg_attr")
74+
|| attr.path.is_ident("classattr")
75+
|| attr.path.is_ident("pyo3")
76+
{
77+
if let Ok(mut meta) = attr.parse_meta() {
78+
if handle_cfg_feature_pyo3(&mut attr, &mut meta, parse_attr)? {
79+
continue;
80+
}
7781

78-
if parse_attribute(&mut attributes, &meta)? {
79-
continue;
82+
if parse_attribute(&mut attributes, &meta)? {
83+
continue;
84+
}
8085
}
8186
}
8287
new_attrs.push(attr)

0 commit comments

Comments
 (0)