Skip to content

Commit 603261d

Browse files
committed
Perf optimize these deep IT tests
.appendElement needs a parser which it gets by scanning up the whole tree, so was O(n^2).
1 parent f0d8782 commit 603261d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/test/java/org/jsoup/nodes/ElementIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void testFastReparentExistingContent() {
8585
Document doc = new Document("https://example.com/");
8686
Element el = doc.body();
8787
for (int i = 0; i <= 50000; i++) {
88-
el = el.appendElement("p");
88+
el = el.appendChild(doc.createElement("p")).firstElementChild();
8989
}
9090
assertFalse(doc.hasText());
9191
el.text("Hello");
@@ -98,7 +98,7 @@ public void testFastReparentExistingContent() {
9898
Document doc = new Document("https://example.com/");
9999
Element el = doc.body();
100100
for (int i = 0; i <= 50000; i++) {
101-
el = el.appendElement("p");
101+
el = el.appendChild(doc.createElement("p")).firstElementChild();
102102
}
103103
Element script = el.appendElement("script");
104104
script.text("script"); // holds data nodes, so inserts as data, not text
@@ -113,7 +113,7 @@ public void testFastReparentExistingContent() {
113113
Element el = doc.body();
114114
int num = 50000;
115115
for (int i = 0; i <= num; i++) {
116-
el = el.appendElement("p");
116+
el = el.appendChild(doc.createElement("p")).firstElementChild();
117117
}
118118
Elements parents = el.parents();
119119
assertEquals(num+2, parents.size()); // +2 for html and body

0 commit comments

Comments
 (0)