Browse Source

+ Added TDOMNode_WithChildren.InternalAppend, and used it to build node tree when cloning nodes. This speeds up the scenario when cloneNode() and node lists are used together, because the document is no longer marked as modified at each call to cloneNode.

git-svn-id: trunk@14147 -
sergei 15 years ago
parent
commit
6a8064fc3f
1 changed files with 14 additions and 1 deletions
  1. 14 1
      packages/fcl-xml/src/dom.pp

+ 14 - 1
packages/fcl-xml/src/dom.pp

@@ -290,6 +290,7 @@ type
     function DetachChild(OldChild: TDOMNode): TDOMNode; override;
     function HasChildNodes: Boolean; override;
     function FindNode(const ANodeName: DOMString): TDOMNode; override;
+    procedure InternalAppend(NewChild: TDOMNode);
   end;
 
 
@@ -1418,6 +1419,18 @@ begin
   Result := OldChild;
 end;
 
+procedure TDOMNode_WithChildren.InternalAppend(NewChild: TDOMNode);
+begin
+  if Assigned(FFirstChild) then
+  begin
+    FLastChild.FNextSibling := NewChild;
+    NewChild.FPreviousSibling := FLastChild;
+  end else
+    FFirstChild := NewChild;
+  FLastChild := NewChild;
+  NewChild.FParentNode := Self;
+end;
+
 function TDOMNode_WithChildren.HasChildNodes: Boolean;
 begin
   Result := Assigned(FFirstChild);
@@ -1444,7 +1457,7 @@ begin
   node := FirstChild;
   while Assigned(node) do
   begin
-    ACopy.AppendChild(node.CloneNode(True, ACloneOwner));
+    TDOMNode_WithChildren(ACopy).InternalAppend(node.CloneNode(True, ACloneOwner));
     node := node.NextSibling;
   end;
 end;