Skip to content

Commit 2c32792

Browse files
committed
simplify code
1 parent 064699c commit 2c32792

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/main/java/org/htmlunit/html/DomNode.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,21 @@ protected void detach() {
11611161
* Cuts off all relationships this node has with siblings and parents.
11621162
*/
11631163
protected void basicRemove() {
1164+
basicDetach();
1165+
1166+
nextSibling_ = null;
1167+
previousSibling_ = null;
1168+
parent_ = null;
1169+
attachedToPage_ = false;
1170+
for (final DomNode descendant : getDescendants()) {
1171+
descendant.attachedToPage_ = false;
1172+
}
1173+
}
1174+
1175+
/**
1176+
* Cuts off all relationships this node has with siblings and parents.
1177+
*/
1178+
private void basicDetach() {
11641179
if (parent_ != null && parent_.firstChild_ == this) {
11651180
parent_.firstChild_ = nextSibling_;
11661181
}
@@ -1173,14 +1188,6 @@ else if (previousSibling_ != null && previousSibling_.nextSibling_ == this) {
11731188
if (parent_ != null && parent_.getLastChild() == this) {
11741189
parent_.firstChild_.previousSibling_ = previousSibling_;
11751190
}
1176-
1177-
nextSibling_ = null;
1178-
previousSibling_ = null;
1179-
parent_ = null;
1180-
attachedToPage_ = false;
1181-
for (final DomNode descendant : getDescendants()) {
1182-
descendant.attachedToPage_ = false;
1183-
}
11841191
}
11851192

11861193
private void fireRemoval(final DomNode exParent) {
@@ -1381,20 +1388,7 @@ public void moveBefore(final DomNode movedDomNode) {
13811388
return;
13821389
}
13831390

1384-
// remove movedDomNode from tree (detach() does too mutch)
1385-
if (movedDomNode.parent_ != null && movedDomNode.parent_.firstChild_ == movedDomNode) {
1386-
movedDomNode.parent_.firstChild_ = movedDomNode.nextSibling_;
1387-
}
1388-
else if (movedDomNode.previousSibling_ != null && movedDomNode.previousSibling_.nextSibling_ == movedDomNode) {
1389-
movedDomNode.previousSibling_.nextSibling_ = movedDomNode.nextSibling_;
1390-
}
1391-
if (movedDomNode.nextSibling_ != null && movedDomNode.nextSibling_.previousSibling_ == movedDomNode) {
1392-
movedDomNode.nextSibling_.previousSibling_ = movedDomNode.previousSibling_;
1393-
}
1394-
if (movedDomNode.parent_ != null && movedDomNode.parent_.getLastChild() == movedDomNode) {
1395-
movedDomNode.parent_.firstChild_.previousSibling_ = movedDomNode.previousSibling_;
1396-
}
1397-
1391+
movedDomNode.basicDetach();
13981392
basicInsertBefore(movedDomNode);
13991393

14001394
fireAddition(movedDomNode);

0 commit comments

Comments
 (0)