Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove one allocation from visit_children #49

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,7 @@ impl<'tu> Entity<'tu> {
/// is the parent of that AST entity. The return value of the callback determines how visitation
/// will proceed.
pub fn visit_children<F: FnMut(Entity<'tu>, Entity<'tu>) -> EntityVisitResult>(
&self, f: F
&self, mut f: F
) -> bool {
trait EntityCallback<'tu> {
fn call(&mut self, entity: Entity<'tu>, parent: Entity<'tu>) -> EntityVisitResult;
Expand All @@ -2523,15 +2523,15 @@ impl<'tu> Entity<'tu> {
) -> CXChildVisitResult {
unsafe {
let &mut (tu, ref mut callback) =
&mut *(data as *mut (&TranslationUnit, Box<dyn EntityCallback>));
&mut *(data as *mut (&TranslationUnit, &mut dyn EntityCallback));

let entity = Entity::from_raw(cursor, tu);
let parent = Entity::from_raw(parent, tu);
callback.call(entity, parent) as c_int
}
}

let mut data = (self.tu, Box::new(f) as Box<dyn EntityCallback>);
let mut data = (self.tu, &mut f as &mut dyn EntityCallback);
unsafe { clang_visitChildren(self.raw, visit, utility::addressof(&mut data)) != 0 }
}

Expand Down