Skip to content

Commit 45121d1

Browse files
committed
fix: update clean text cache impl & remove child impl
1 parent acabd28 commit 45121d1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

float-pigment-forest/src/node.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl Node {
275275
}
276276
self.node_type.replace(node_type);
277277
}
278-
if node_type == NodeType::Text {
278+
if node_type == NodeType::Text && node_type != prev_type {
279279
*self.measure_cache.get() = Some(Box::new(LruCache::new(CACHE_SIZE)));
280280
*self.baseline_cache.get() = Some(Box::new(LruCache::new(CACHE_SIZE)));
281281
}
@@ -548,16 +548,21 @@ impl ChildOperation for Node {
548548
if self.children_len() == 0 {
549549
return;
550550
}
551-
if let Some((idx, node)) = self
551+
let child_idx_opt = self
552552
.children
553553
.borrow()
554554
.iter()
555-
.enumerate()
556-
.find(|(_, node)| std::ptr::eq(**node, child))
557-
{
558-
(**node).set_parent(None);
559-
(*self.children.as_ptr()).remove(idx);
555+
.position(|node| std::ptr::eq(*node, child));
556+
if let Some(child_idx) = child_idx_opt {
557+
let node = {
558+
let mut children = self.children.borrow_mut();
559+
let node = children[child_idx];
560+
children.remove(child_idx);
561+
node
562+
};
563+
(*node).set_parent(None);
560564
}
565+
561566
self.mark_dirty_propagate();
562567
}
563568
unsafe fn remove_child_at(&self, idx: usize) {

0 commit comments

Comments
 (0)