-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix O(N) performance of DOMNode::replaceChild() and DOMNode::removeCh…
…ild() Don't loop over all children to determine if the target node really is a child, just trust the parent pointer. Add tests.
- Loading branch information
Showing
4 changed files
with
86 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
removeChild() where the node is not a child | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
$document = new DOMDocument(); | ||
$real_parent = $document->createElement('real'); | ||
$parent = $document->createElement('p'); | ||
$child1 = $document->createElement('child1'); | ||
$child2 = $document->createElement('child2'); | ||
$real_parent->appendChild($child1); | ||
$parent->appendChild($child2); | ||
try { | ||
$parent->removeChild($child1); | ||
} catch (DOMException $e) { | ||
echo "DOMException: " . $e->getMessage(); | ||
} | ||
--EXPECT-- | ||
DOMException: Not Found Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
replaceChild() where the old node is not a child | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
$document = new DOMDocument(); | ||
$real_parent = $document->createElement('real'); | ||
$parent = $document->createElement('p'); | ||
$child1 = $document->createElement('child1'); | ||
$child2 = $document->createElement('child2'); | ||
$child3 = $document->createElement('child3'); | ||
$real_parent->appendChild($child1); | ||
$parent->appendChild($child2); | ||
try { | ||
$parent->replaceChild($child3, $child1); | ||
} catch (DOMException $e) { | ||
echo "DOMException: " . $e->getMessage(); | ||
} | ||
--EXPECT-- | ||
DOMException: Not Found Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
replaceChild() where the new node is a grandparent of the old node | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
$document = new DOMDocument(); | ||
$a = $document->createElement('a'); | ||
$b = $document->createElement('b'); | ||
$c = $document->createElement('c'); | ||
$a->appendChild($b); | ||
$b->appendChild($c); | ||
try { | ||
$b->replaceChild($a, $c); | ||
} catch (DOMException $e) { | ||
echo "DOMException: " . $e->getMessage(); | ||
} | ||
--EXPECT-- | ||
DOMException: Hierarchy Request Error |