Skip to content

Commit d5f88e4

Browse files
committed
append onto a consistent target.
This stops us from creating a larger intermediate value when there's a Text node on either side of an Escaped Text node; we append the Escaped Text to the left-hand Text, and then the right Text on the left-hand Text. Previously, we were appending the Escaped Text to the right-hand Text, and then appending _that_ to the left-hand Text.
1 parent b7afc3f commit d5f88e4

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/parser/mod.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,32 +1904,36 @@ where
19041904
node.insert_before(escaped_text);
19051905
node.detach();
19061906

1907+
let mut target = escaped_text;
1908+
19071909
// We only need look one left and one right, as all adjacent
19081910
// Text nodes are coalesced already.
1909-
if let Some(after) = escaped_text.next_sibling() {
1911+
if let Some(before) = target.previous_sibling() {
1912+
let mut before_mut = before.data_mut();
1913+
if let Some(before_text) = before_mut.value.text_mut() {
1914+
let target_data = target.data();
1915+
let target_text = target_data.value.text().unwrap();
1916+
before_text.to_mut().push_str(target_text);
1917+
before_mut.sourcepos.end = target_data.sourcepos.end;
1918+
target.detach();
1919+
1920+
target = before;
1921+
}
1922+
}
1923+
1924+
if let Some(after) = target.next_sibling() {
19101925
if let Some(after_text) = after.data().value.text() {
1911-
let mut escaped_text_mut = escaped_text.data_mut();
1912-
escaped_text_mut
1926+
let mut target_mut = target.data_mut();
1927+
target_mut
19131928
.value
19141929
.text_mut()
19151930
.unwrap()
19161931
.to_mut()
19171932
.push_str(after_text);
1918-
escaped_text_mut.sourcepos.end = after.data().sourcepos.end;
1933+
target_mut.sourcepos.end = after.data().sourcepos.end;
19191934
after.detach();
19201935
}
19211936
}
1922-
1923-
if let Some(before) = escaped_text.previous_sibling() {
1924-
let mut before_mut = before.data_mut();
1925-
if let Some(before_text) = before_mut.value.text_mut() {
1926-
let escaped_text_data = escaped_text.data();
1927-
let escaped_text_text = escaped_text_data.value.text().unwrap();
1928-
before_text.to_mut().push_str(escaped_text_text);
1929-
before_mut.sourcepos.end = escaped_text_data.sourcepos.end;
1930-
escaped_text.detach();
1931-
}
1932-
}
19331937
}
19341938

19351939
// Push children onto work stack in reverse order so they are

0 commit comments

Comments
 (0)