Skip to content

Commit

Permalink
remove one allocation from visit_children (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-xiaoming committed Dec 31, 2023
1 parent 79f83c7 commit d46df8e
Showing 1 changed file with 3 additions and 3 deletions.
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

0 comments on commit d46df8e

Please sign in to comment.