pub struct NodePool { /* private fields */ }Expand description
A reusable pool of A11yNode allocations, keyed by NodeId.
Reduces per-frame heap allocations when the accessibility tree is rebuilt
on every frame: rather than dropping and re-allocating every node, the pool
keeps previously-allocated structs (and their internal Vec allocations)
on a free list.
§Invariants
Implementations§
Source§impl NodePool
impl NodePool
Sourcepub fn alloc(&mut self, id: NodeId, node: A11yNode)
pub fn alloc(&mut self, id: NodeId, node: A11yNode)
Place node into the active map under id.
If a node with the same id already exists it is silently replaced and
the old node is dropped (not returned to the free list, to avoid a
same-id duplicate).
Sourcepub fn alloc_recycled(
&mut self,
id: NodeId,
role: WidgetRole,
label: Option<String>,
) -> &mut A11yNode
pub fn alloc_recycled( &mut self, id: NodeId, role: WidgetRole, label: Option<String>, ) -> &mut A11yNode
Allocate a node slot, optionally reusing memory from the free list.
If a free node is available its struct is taken from the free list and
reset to the supplied id, role, and label before being placed in
the active map. Otherwise a fresh node is created.
This is the preferred allocation path for hot paths that care about minimising heap allocation churn.
Sourcepub fn get_mut(&mut self, id: &NodeId) -> Option<&mut A11yNode>
pub fn get_mut(&mut self, id: &NodeId) -> Option<&mut A11yNode>
Retrieve a mutable reference to an active node.
Sourcepub fn recycle(&mut self)
pub fn recycle(&mut self)
Move all active nodes back to the free list for reuse next frame.
After this call active_count() == 0 and free_count() reflects the
total number of recycled nodes.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of currently-active nodes.
Sourcepub fn free_count(&self) -> usize
pub fn free_count(&self) -> usize
Number of nodes available for reuse.
Sourcepub fn iter_active(&self) -> impl Iterator<Item = (&NodeId, &A11yNode)>
pub fn iter_active(&self) -> impl Iterator<Item = (&NodeId, &A11yNode)>
Iterate over all active nodes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NodePool
impl RefUnwindSafe for NodePool
impl Send for NodePool
impl Sync for NodePool
impl Unpin for NodePool
impl UnsafeUnpin for NodePool
impl UnwindSafe for NodePool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more