Author: atsushi
Date: 2006-02-20 07:18:54 -0500 (Mon, 20 Feb 2006)
New Revision: 57062
Modified:
trunk/mcs/class/System.XML/System.Xml/ChangeLog
trunk/mcs/class/System.XML/System.Xml/XmlNodeReaderImpl.cs
Log:
2006-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlNodeReaderImpl.cs : Reimplemented Read(). Points are:
- reduced call to NextSibling which is very unlikely to be inlined
- reorganized conditioning to avoid extra check
- added description on each returning branch.
- And then, removed unused code.
It is 1.5x faster than before.
Modified: trunk/mcs/class/System.XML/System.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml/ChangeLog 2006-02-20 10:20:48 UTC
(rev 57061)
+++ trunk/mcs/class/System.XML/System.Xml/ChangeLog 2006-02-20 12:18:54 UTC
(rev 57062)
@@ -1,3 +1,12 @@
+2006-02-20 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlNodeReaderImpl.cs : Reimplemented Read(). Points are:
+ - reduced call to NextSibling which is very unlikely to be inlined
+ - reorganized conditioning to avoid extra check
+ - added description on each returning branch.
+ - And then, removed unused code.
+ It is 1.5x faster than before.
+
2006-02-17 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlElement.cs : NextSibling could be effectively computed using
Modified: trunk/mcs/class/System.XML/System.Xml/XmlNodeReaderImpl.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml/XmlNodeReaderImpl.cs 2006-02-20
10:20:48 UTC (rev 57061)
+++ trunk/mcs/class/System.XML/System.Xml/XmlNodeReaderImpl.cs 2006-02-20
12:18:54 UTC (rev 57062)
@@ -59,21 +59,8 @@
ReadState state = ReadState.Initial;
int depth;
bool isEndElement;
- bool alreadyRead;
+ bool ignoreStartNode;
- /*
- private XmlNode ownerLinkedNode {
- get {
- if (current.ParentNode != null &&
current.ParentNode.NodeType == XmlNodeType.Attribute)
- return ((XmlAttribute)
current.ParentNode).OwnerElement;
- else if (current.NodeType ==
XmlNodeType.Attribute)
- return ((XmlAttribute)
current).OwnerElement;
- else
- return current;
- }
- }
- */
-
#region Constructor
internal XmlNodeReaderImpl (XmlNodeReaderImpl entityContainer)
@@ -92,10 +79,8 @@
case XmlNodeType.Document:
case XmlNodeType.DocumentFragment:
case XmlNodeType.EntityReference:
+ ignoreStartNode = true;
break;
- default:
- alreadyRead = true;
- break;
}
}
@@ -648,14 +633,6 @@
}
}
- private void MoveToParentElement ()
- {
- // This is buggy. It is not only the case when
EndElement = true.
- isEndElement = true;
- depth--;
- current = current.ParentNode;
- }
-
public override bool MoveToElement ()
{
if (current == null)
@@ -710,26 +687,6 @@
}
}
- private bool MoveToNextSibling ()
- {
- if (alreadyRead) {
- alreadyRead = false;
- return current != null;
- }
- if (current.NextSibling != null) {
- isEndElement = false;
- current = current.NextSibling;
- } else {
- MoveToParentElement ();
- }
- if (current == null) {
- state = ReadState.EndOfFile;
- return false;
- }
- else
- return true;
- }
-
public override bool Read ()
{
// FIXME: at some stage inlining might work effectively.
@@ -753,10 +710,8 @@
current = startNode;
state = ReadState.Interactive;
// when startNode is document or fragment
- if (!alreadyRead)
+ if (ignoreStartNode)
current = startNode.FirstChild;
- else
- alreadyRead = false;
if (current == null) {
state = ReadState.Error;
return false;
@@ -766,55 +721,70 @@
MoveToElement ();
- if (alreadyRead) {
- alreadyRead = false;
- return current != null;
+ // don't step into EntityReference's children. Also
+ // avoid re-entering children of already-consumed
+ // element (i.e. when it is regarded as EndElement).
+ XmlNode firstChild =
+ !isEndElement && current.NodeType !=
XmlNodeType.EntityReference ?
+ current.FirstChild : null;
+ if (firstChild != null) {
+ isEndElement = false;
+ current = firstChild;
+ depth++;
+ return true;
}
- bool isEnd = false;
-
- if (IsEmptyElement || isEndElement) {
- // Then go up and move to next.
- // If no more nodes, then set EOF.
- isEndElement = false;
- if (current.ParentNode == null
- || current.ParentNode.NodeType ==
XmlNodeType.Document
- || current.ParentNode.NodeType ==
XmlNodeType.DocumentFragment
- || current == startNode) {
- isEnd = true;
- } else if (current.NextSibling == null) {
- depth--;
- current = current.ParentNode;
+ if (current == startNode) { // Currently it is on the
start node.
+ if (IsEmptyElement || isEndElement) {
+ // The start node is already consumed.
+ isEndElement = false;
+ current = null;
+ state = ReadState.EndOfFile;
+ return false;
+ } else {
+ // The start node is the only element
+ // which should be processed. Now it
+ // is set as EndElement.
isEndElement = true;
return true;
- } else {
- current = current.NextSibling;
- return true;
}
}
+ if (!isEndElement && !IsEmptyElement &&
+ current.NodeType == XmlNodeType.Element) {
+ // element, currently not EndElement, and has
+ // no child. (such as <foo></foo>, which
+ // should become EndElement).
+ isEndElement = true;
+ return true;
+ }
- if (current.NextSibling == null
- && current.ParentNode is XmlEntityReference)
- isEnd = true;
+ // If NextSibling is available, move to there.
+ XmlNode next = current.NextSibling;
+ if (next != null) {
+ isEndElement = false;
+ current = next;
+ return true;
+ }
- if (isEnd) {
+ // Otherwise, parent.
+ XmlNode parent = current.ParentNode;
+ if (parent == null || parent == startNode &&
ignoreStartNode) {
+ // Parent is not available, or reached to
+ // the start node. This reader never sets
+ // startNode as current if it was originally
+ // ignored (e.g. startNode is XmlDocument).
+ isEndElement = false;
current = null;
state = ReadState.EndOfFile;
return false;
- }
-
- if (!isEndElement && current.FirstChild != null &&
current.NodeType != XmlNodeType.EntityReference) {
- isEndElement = false;
- current = current.FirstChild;
- depth++;
- } else if (current.NodeType == XmlNodeType.Element) {
+ } else {
+ // Parent was available, so return it as
+ // EndElement.
+ current = parent;
+ depth--;
isEndElement = true;
- if (current.FirstChild != null)
- depth--;
- } else
- MoveToNextSibling ();
-
- return current != null;
+ return true;
+ }
}
public override bool ReadAttributeValue ()
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches