Skip to content

Commit 515482e

Browse files
committed
small optimization
1 parent 5d78906 commit 515482e

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/main/java/org/htmlunit/cyberneko/HTMLTagBalancer.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,30 @@ public void endDocument(final Augmentations augs) throws XNIException {
551551
* at the end of document
552552
*/
553553
private void consumeBufferedEndElements() {
554-
if (endElementsBuffer_.isEmpty()) {
554+
final int s = endElementsBuffer_.size();
555+
if (s == 0) {
556+
return;
557+
}
558+
559+
if (s == 1) {
560+
final ElementEntry entry = endElementsBuffer_.get(0);
561+
forcedEndElement_ = true;
562+
endElement(entry.name_, entry.augs_);
563+
endElementsBuffer_.clear();
564+
return;
565+
}
566+
567+
if (s == 2) {
568+
final ElementEntry entry0 = endElementsBuffer_.get(0);
569+
final ElementEntry entry1 = endElementsBuffer_.get(1);
570+
forcedEndElement_ = true;
571+
endElement(entry0.name_, entry0.augs_);
572+
endElement(entry1.name_, entry1.augs_);
573+
endElementsBuffer_.clear();
555574
return;
556575
}
557576

558577
final List<ElementEntry> toConsume = new ArrayList<>(endElementsBuffer_);
559-
endElementsBuffer_.clear();
560578
for (final ElementEntry entry : toConsume) {
561579
forcedEndElement_ = true;
562580
endElement(entry.name_, entry.augs_);

0 commit comments

Comments
 (0)