@@ -1,6 +1,6 @@
1use crate::{
1use crate::{
2 cached_set::{CacheId, CachedSet},
2 cached_set::{CacheId, CachedSet},
3− change_list::ChangeList,
3+ change_list::ChangeListBuilder,
4 events::EventsRegistry,
4 events::EventsRegistry,
5 node::{Attribute, ElementNode, Listener, Node, NodeKind, TextNode},
5 node::{Attribute, ElementNode, Listener, Node, NodeKind, TextNode},
@@ -8,7 +8,7 @@ use std::cmp;
9pub(crate) fn diff(
9pub(crate) fn diff(
10 cached_set: &CachedSet,
10 cached_set: &CachedSet,
11− change_list: &mut ChangeList,
11+ change_list: &mut ChangeListBuilder,
12 registry: &mut EventsRegistry,
12 registry: &mut EventsRegistry,
13 old: Node,
13 old: Node,
14 new: Node,
14 new: Node,
@@ -22,7 +22,7 @@ pub(crate) fn diff(
22 debug!(" both are text nodes");
22 debug!(" both are text nodes");
23 if new_text != old_text {
23 if new_text != old_text {
24 debug!(" text needs updating");
24 debug!(" text needs updating");
25− change_list.emit_set_text(new_text);
25+ change_list.set_text(new_text);
@@ -30,7 +30,7 @@ pub(crate) fn diff(
30 debug!(" replacing a text node with an element");
30 debug!(" replacing a text node with an element");
31 create(cached_set, change_list, registry, new, cached_roots);
31 create(cached_set, change_list, registry, new, cached_roots);
32 registry.remove_subtree(&old);
32 registry.remove_subtree(&old);
33− change_list.emit_replace_with();
33+ change_list.replace_with();
36 (&NodeKind::Element(_), &NodeKind::Text(_)) => {
36 (&NodeKind::Element(_), &NodeKind::Text(_)) => {
@@ -38,7 +38,7 @@ pub(crate) fn diff(
38 create(cached_set, change_list, registry, new, cached_roots);
38 create(cached_set, change_list, registry, new, cached_roots);
39 // Note: text nodes cannot have event listeners, so we don't need to
39 // Note: text nodes cannot have event listeners, so we don't need to
40 // remove the old node's listeners from our registry her.
40 // remove the old node's listeners from our registry her.
41− change_list.emit_replace_with();
41+ change_list.replace_with();
@@ -62,7 +62,7 @@ pub(crate) fn diff(
62 debug!(" different tag names or namespaces; creating new element and replacing old element");
62 debug!(" different tag names or namespaces; creating new element and replacing old element");
63 create(cached_set, change_list, registry, new, cached_roots);
63 create(cached_set, change_list, registry, new, cached_roots);
64 registry.remove_subtree(&old);
64 registry.remove_subtree(&old);
65− change_list.emit_replace_with();
65+ change_list.replace_with();
68 diff_listeners(change_list, registry, old_listeners, new_listeners);
68 diff_listeners(change_list, registry, old_listeners, new_listeners);
@@ -99,7 +99,7 @@ pub(crate) fn diff(
99 let new = cached_set.get(c.id);
99 let new = cached_set.get(c.id);
100 create(cached_set, change_list, registry, new, cached_roots);
100 create(cached_set, change_list, registry, new, cached_roots);
101 registry.remove_subtree(&old);
101 registry.remove_subtree(&old);
102− change_list.emit_replace_with();
102+ change_list.replace_with();
105 // Old cached node and new non-cached node. Again, assume that they are
105 // Old cached node and new non-cached node. Again, assume that they are
@@ -107,13 +107,13 @@ pub(crate) fn diff(
107 (_, &NodeKind::Cached(_)) => {
107 (_, &NodeKind::Cached(_)) => {
108 create(cached_set, change_list, registry, new, cached_roots);
108 create(cached_set, change_list, registry, new, cached_roots);
109 registry.remove_subtree(&old);
109 registry.remove_subtree(&old);
110− change_list.emit_replace_with();
110+ change_list.replace_with();
115fn diff_listeners(
115fn diff_listeners(
116− change_list: &mut ChangeList,
116+ change_list: &mut ChangeListBuilder,
117 registry: &mut EventsRegistry,
117 registry: &mut EventsRegistry,
118 old: &[Listener],
118 old: &[Listener],
119 new: &[Listener],
119 new: &[Listener],
@@ -130,12 +130,12 @@ fn diff_listeners(
131 for old_l in old {
131 for old_l in old {
132 if new_l.event == old_l.event {
132 if new_l.event == old_l.event {
133− change_list.emit_update_event_listener(new_l);
133+ change_list.update_event_listener(new_l);
134 continue 'outer1;
134 continue 'outer1;
138− change_list.emit_new_event_listener(new_l);
138+ change_list.new_event_listener(new_l);
141 'outer2: for old_l in old {
141 'outer2: for old_l in old {
@@ -146,28 +146,28 @@ fn diff_listeners(
146 continue 'outer2;
146 continue 'outer2;
149− change_list.emit_remove_event_listener(old_l.event);
149+ change_list.remove_event_listener(old_l.event);
153−fn diff_attributes(change_list: &mut ChangeList, old: &[Attribute], new: &[Attribute]) {
153+fn diff_attributes(change_list: &mut ChangeListBuilder, old: &[Attribute], new: &[Attribute]) {
154 debug!(" updating attributes");
154 debug!(" updating attributes");
156 // Do O(n^2) passes to add/update and remove attributes, since
156 // Do O(n^2) passes to add/update and remove attributes, since
157 // there are almost always very few attributes.
157 // there are almost always very few attributes.
158 'outer: for new_attr in new {
158 'outer: for new_attr in new {
159 if new_attr.is_volatile() {
159 if new_attr.is_volatile() {
160− change_list.emit_set_attribute(new_attr.name, new_attr.value);
160+ change_list.set_attribute(new_attr.name, new_attr.value);
162 for old_attr in old {
162 for old_attr in old {
163 if old_attr.name == new_attr.name {
163 if old_attr.name == new_attr.name {
164 if old_attr.value != new_attr.value {
164 if old_attr.value != new_attr.value {
165− change_list.emit_set_attribute(new_attr.name, new_attr.value);
165+ change_list.set_attribute(new_attr.name, new_attr.value);
167 continue 'outer;
167 continue 'outer;
170− change_list.emit_set_attribute(new_attr.name, new_attr.value);
170+ change_list.set_attribute(new_attr.name, new_attr.value);
@@ -177,13 +177,13 @@ fn diff_attributes(change_list: &mut ChangeList, old: &[Attribute], new: &[Attri
177 continue 'outer2;
177 continue 'outer2;
180− change_list.emit_remove_attribute(old_attr.name);
180+ change_list.remove_attribute(old_attr.name);
184fn diff_children(
184fn diff_children(
185 cached_set: &CachedSet,
185 cached_set: &CachedSet,
186− change_list: &mut ChangeList,
186+ change_list: &mut ChangeListBuilder,
187 registry: &mut EventsRegistry,
187 registry: &mut EventsRegistry,
188 old: &[Node],
188 old: &[Node],
189 new: &[Node],
189 new: &[Node],
@@ -203,11 +203,11 @@ fn diff_children(
203 .enumerate()
203 .enumerate()
205 if i == 0 {
205 if i == 0 {
206− change_list.emit_push_first_child();
206+ change_list.push_first_child();
207 pushed = true;
207 pushed = true;
209 debug_assert!(pushed);
209 debug_assert!(pushed);
210− change_list.emit_pop_push_next_sibling();
210+ change_list.pop_push_next_sibling();
@@ -223,18 +223,18 @@ fn diff_children(
223 if old_children.next().is_some() {
223 if old_children.next().is_some() {
224 debug!(" removing extra old children");
224 debug!(" removing extra old children");
225 debug_assert!(new_children.next().is_none());
225 debug_assert!(new_children.next().is_none());
226− if !pushed {
226+ if pushed {
227− change_list.emit_push_first_child();
227+ change_list.pop_push_next_sibling();
229− change_list.emit_pop_push_next_sibling();
229+ change_list.push_first_child();
231− change_list.emit_remove_self_and_next_siblings();
231+ change_list.remove_self_and_next_siblings();
232 pushed = false;
232 pushed = false;
234 debug!(" creating new children");
234 debug!(" creating new children");
235 for (i, new_child) in new_children.enumerate() {
235 for (i, new_child) in new_children.enumerate() {
236 if i == 0 && pushed {
236 if i == 0 && pushed {
237− change_list.emit_pop();
237+ change_list.pop();
238 pushed = false;
238 pushed = false;
@@ -244,26 +244,26 @@ fn diff_children(
244 new_child.clone(),
244 new_child.clone(),
245 cached_roots,
245 cached_roots,
247− change_list.emit_append_child();
247+ change_list.append_child();
251 debug!(" done updating children");
251 debug!(" done updating children");
252 if pushed {
252 if pushed {
253− change_list.emit_pop();
253+ change_list.pop();
257fn create(
257fn create(
258 cached_set: &CachedSet,
258 cached_set: &CachedSet,
259− change_list: &mut ChangeList,
259+ change_list: &mut ChangeListBuilder,
260 registry: &mut EventsRegistry,
260 registry: &mut EventsRegistry,
261 node: Node,
261 node: Node,
262 cached_roots: &mut bumpalo::collections::Vec<CacheId>,
262 cached_roots: &mut bumpalo::collections::Vec<CacheId>,
264 match node.kind {
264 match node.kind {
265 NodeKind::Text(TextNode { text }) => {
265 NodeKind::Text(TextNode { text }) => {
266− change_list.emit_create_text_node(text);
266+ change_list.create_text_node(text);
268 NodeKind::Element(ElementNode {
268 NodeKind::Element(ElementNode {
269 tag_name,
269 tag_name,
@@ -273,22 +273,18 @@ fn create(
273 namespace,
273 namespace,
275 if let Some(namespace) = namespace {
275 if let Some(namespace) = namespace {
276− change_list.emit_create_element_ns(tag_name, namespace);
276+ change_list.create_element_ns(tag_name, namespace);
278− change_list.emit_create_element(tag_name);
278+ change_list.create_element(tag_name);
280 for l in listeners {
280 for l in listeners {
282 registry.add(l);
282 registry.add(l);
284− change_list.emit_new_event_listener(l);
284+ change_list.new_event_listener(l);
286 for attr in attributes {
286 for attr in attributes {
287− if namespace.is_none() || attr.name.starts_with("xmlns") {
287+ change_list.set_attribute(&attr.name, &attr.value);
288− change_list.emit_set_attribute(&attr.name, &attr.value);
290− change_list.emit_set_attribute_ns(&attr.name, &attr.value);
293 for child in children {
289 for child in children {
@@ -298,7 +294,7 @@ fn create(
298 child.clone(),
294 child.clone(),
299 cached_roots,
295 cached_roots,
301− change_list.emit_append_child();
297+ change_list.append_child();
304 NodeKind::Cached(c) => {
300 NodeKind::Cached(c) => {