Author: atsushi
Date: 2005-03-15 00:43:56 -0500 (Tue, 15 Mar 2005)
New Revision: 41824
Modified:
trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder2.cs
trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentWriter2.cs
trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathNode2.cs
Log:
2004-03-15 Atsushi Enomoto <[EMAIL PROTECTED]>
* DTMXPathDocumentWriter2.cs : Eliminated Depth as well as -builder.
* DTMXPathNode2.cs, DTMXPathDocumentBuilder2.cs :
Eliminated Depth at all.
Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog 2005-03-15 04:34:36 UTC
(rev 41823)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog 2005-03-15 05:43:56 UTC
(rev 41824)
@@ -1,5 +1,11 @@
2004-03-15 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * DTMXPathDocumentWriter2.cs : Eliminated Depth as well as -builder.
+ * DTMXPathNode2.cs, DTMXPathDocumentBuilder2.cs :
+ Eliminated Depth at all.
+
+2004-03-15 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* DTMXPathDocumentBuilder2.cs : Eliminating Depth. Store parent index
stack instead of depending on Depth.
Just use hasAttributes and hasLocalNs instead of indices.
Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder2.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder2.cs
2005-03-15 04:34:36 UTC (rev 41823)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder2.cs
2005-03-15 05:43:56 UTC (rev 41824)
@@ -166,7 +166,7 @@
// index 0 is dummy. No node (including Root) is
assigned to this index
// So that we can easily compare index != 0 instead of
index < 0.
// (Difference between jnz or jbe in 80x86.)
- AddNode (0, 0, 0, 0, XPathNodeType.All, 0, false, 0, 0,
0, 0, 0, 0, 0, 0);
+ AddNode (0, 0, 0, XPathNodeType.All, 0, false, 0, 0, 0,
0, 0, 0, 0, 0);
nodeIndex++;
AddAttribute (0, 0, 0, 0, 0, 0, 0);
AddNsNode (0, 0, 0, 0);
@@ -174,7 +174,7 @@
AddNsNode (1, AtomicIndex ("xml"), AtomicIndex
(XmlNamespaces.XML), 0);
// add root.
- AddNode (0, 0, 0, -1, XPathNodeType.Root, AtomicIndex
(xmlReader.BaseURI), false, 0, 0, 0, 0, 0, 1, 0, 0);
+ AddNode (0, 0, 0, XPathNodeType.Root, AtomicIndex
(xmlReader.BaseURI), false, 0, 0, 0, 0, 0, 1, 0, 0);
this.nodeIndex = 1;
this.lastNsInScope = 1;
@@ -268,7 +268,6 @@
AddNode (parent,
0,
prevSibling,
- xmlReader.Depth,
nodeType,
AtomicIndex (xmlReader.BaseURI),
xmlReader.IsEmptyElement,
@@ -362,7 +361,6 @@
AddNode (parent,
0, // dummy:firstAttribute
previousSibling,
- xmlReader.Depth,
XPathNodeType.Element,
AtomicIndex (xmlReader.BaseURI),
xmlReader.IsEmptyElement,
@@ -388,12 +386,13 @@
}
if (!nodes [nodeIndex].IsEmptyElement) {
- parentStack [++parentStackIndex] = nodeIndex;
+ parentStackIndex++;
if (parentStack.Length == parentStackIndex) {
int [] tmp = new int [parentStackIndex
* 2];
Array.Copy (parentStack, tmp,
parentStackIndex);
parentStack = tmp;
}
+ parentStack [parentStackIndex] = nodeIndex;
}
}
@@ -509,7 +508,7 @@
}
// Here followings are skipped: firstChild, nextSibling,
- public void AddNode (int parent, int firstAttribute, int
previousSibling, int depth, XPathNodeType nodeType, int baseUri, bool
isEmptyElement, int localName, int ns, int prefix, int value, int xmlLang, int
namespaceNode, int lineNumber, int linePosition)
+ public void AddNode (int parent, int firstAttribute, int
previousSibling, XPathNodeType nodeType, int baseUri, bool isEmptyElement, int
localName, int ns, int prefix, int value, int xmlLang, int namespaceNode, int
lineNumber, int linePosition)
{
if (nodes.Length < nodeIndex + 1) {
nodeCapacity *= 4;
@@ -524,7 +523,6 @@
nodes [nodeIndex].FirstAttribute = firstAttribute;
nodes [nodeIndex].PreviousSibling = previousSibling;
nodes [nodeIndex].NextSibling = 0; // dummy
- nodes [nodeIndex].Depth = depth;
nodes [nodeIndex].NodeType = nodeType;
nodes [nodeIndex].BaseURI = baseUri;
nodes [nodeIndex].IsEmptyElement = isEmptyElement;
Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentWriter2.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentWriter2.cs
2005-03-15 04:34:36 UTC (rev 41823)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentWriter2.cs
2005-03-15 05:43:56 UTC (rev 41824)
@@ -85,19 +85,19 @@
int nodeIndex;
int attributeIndex;
int nsIndex;
- int parentForFirstChild;
+ int [] parentStack = new int [10];
+ int parentStackIndex = 0;
// for attribute processing; should be reset per each element.
- int firstAttributeIndex;
- int lastNsIndexInCurrent;
+ bool hasAttributes;
+ bool hasLocalNs;
int attrIndexAtStart;
int nsIndexAtStart;
- int prevSibling;
int lastNsInScope;
// They are only used in Writer
- int writerDepth;
+ int prevSibling;
WriteState state;
bool openNamespace;
bool isClosed;
@@ -127,7 +127,7 @@
// index 0 is dummy. No node (including Root) is
assigned to this index
// So that we can easily compare index != 0 instead of
index < 0.
// (Difference between jnz or jbe in 80x86.)
- AddNode (0, 0, 0, 0, XPathNodeType.All, "", false, "",
"", "", "", "", 0, 0, 0);
+ AddNode (0, 0, 0, XPathNodeType.All, "", false, "", "",
"", "", "", 0, 0, 0);
nodeIndex++;
AddAttribute (0, "", "", "", "", 0, 0);
AddNsNode (0, "", "", 0);
@@ -135,37 +135,28 @@
AddNsNode (1, "xml", XmlNamespaces.XML, 0);
// add root.
- AddNode (0, 0, 0, -1, XPathNodeType.Root, "", false,
"", "", "", "", "", 1, 0, 0);
+ AddNode (0, 0, 0, XPathNodeType.Root, "", false, "",
"", "", "", "", 1, 0, 0);
this.nodeIndex = 1;
this.lastNsInScope = 1;
- this.parentForFirstChild = nodeIndex;
+ parentStack [0] = nodeIndex;
state = WriteState.Content;
}
private int GetParentIndex ()
{
- if (parentForFirstChild >= 0)
- return parentForFirstChild;
-
- int parent = nodeIndex;
- if (nodes [nodeIndex].Depth >= writerDepth) {
- // if not, then current node is parent.
- while (writerDepth <= nodes [parent].Depth)
- parent = nodes [parent].Parent;
- }
- return parent;
+ return parentStack [parentStackIndex];
}
private int GetPreviousSiblingIndex ()
{
+ int parent = parentStack [parentStackIndex];
+ if (parent == nodeIndex)
+ return 0;
int prevSibling = nodeIndex;
- if (parentForFirstChild >= 0)
- prevSibling = 0;
- else
- while (nodes [prevSibling].Depth != writerDepth)
- prevSibling = nodes
[prevSibling].Parent;
+ while (nodes [prevSibling].Parent != parent)
+ prevSibling = nodes [prevSibling].Parent;
return prevSibling;
}
@@ -178,10 +169,8 @@
if (prevSibling != 0)
nodes [prevSibling].NextSibling = nodeIndex;
- if (parentForFirstChild >= 0)
+ if (parent == nodeIndex - 1)
nodes [parent].FirstChild = nodeIndex;
-
- parentForFirstChild = -1;
}
private void CloseStartElement ()
@@ -193,11 +182,15 @@
lastNsInScope = nsIndex;
}
- if (!nodes [nodeIndex].IsEmptyElement)
- parentForFirstChild = nodeIndex;
+ parentStackIndex++;
+ if (parentStack.Length == parentStackIndex) {
+ int [] tmp = new int [parentStackIndex * 2];
+ Array.Copy (parentStack, tmp, parentStackIndex);
+ parentStack = tmp;
+ }
+ parentStack [parentStackIndex] = nodeIndex;
state = WriteState.Content;
- writerDepth++;
}
#region Adding Nodes
@@ -271,7 +264,7 @@
}
// Here followings are skipped: firstChild, nextSibling,
- public void AddNode (int parent, int firstAttribute, int
previousSibling, int depth, XPathNodeType nodeType, string baseUri, bool
isEmptyElement, string localName, string ns, string prefix, string value,
string xmlLang, int namespaceNode, int lineNumber, int linePosition)
+ public void AddNode (int parent, int firstAttribute, int
previousSibling, XPathNodeType nodeType, string baseUri, bool isEmptyElement,
string localName, string ns, string prefix, string value, string xmlLang, int
namespaceNode, int lineNumber, int linePosition)
{
if (nodes.Length < nodeIndex + 1) {
nodeCapacity *= 4;
@@ -286,7 +279,6 @@
nodes [nodeIndex].FirstAttribute = firstAttribute;
nodes [nodeIndex].PreviousSibling = previousSibling;
nodes [nodeIndex].NextSibling = 0; // dummy
- nodes [nodeIndex].Depth = depth;
nodes [nodeIndex].NodeType = nodeType;
nodes [nodeIndex].BaseURI = AtomicIndex (baseUri);
nodes [nodeIndex].IsEmptyElement = isEmptyElement;
@@ -388,7 +380,7 @@
}
// When text after text, just add the value, and return.
- if (nodes [nodeIndex].Depth == writerDepth) {
+ if (nodes [nodeIndex].Parent == parentStack
[parentStackIndex]) {
switch (nodes [nodeIndex].NodeType) {
case XPathNodeType.Text:
case XPathNodeType.SignificantWhitespace:
@@ -408,7 +400,6 @@
AddNode (parent,
0, // attribute
prevSibling,
- writerDepth,
XPathNodeType.Text,
null,
false,
@@ -447,7 +438,6 @@
AddNode (parent,
0, // attribute
prevSibling,
- writerDepth,
XPathNodeType.Comment,
null,
false,
@@ -471,7 +461,6 @@
AddNode (parent,
0, // attribute
prevSibling,
- writerDepth,
XPathNodeType.ProcessingInstruction,
null,
false,
@@ -495,7 +484,6 @@
AddNode (parent,
0, // attribute
prevSibling,
- writerDepth,
XPathNodeType.Whitespace,
null,
false,
@@ -552,7 +540,6 @@
AddNode (parent,
0, // dummy:firstAttribute
previousSibling,
- writerDepth,
XPathNodeType.Element,
null,
false,
@@ -568,8 +555,8 @@
private void PrepareStartElement (int previousSibling)
{
- firstAttributeIndex = 0;
- lastNsIndexInCurrent = 0;
+ hasAttributes = false;
+ hasLocalNs = false;
attrIndexAtStart = attributeIndex;
nsIndexAtStart = nsIndex;
@@ -599,13 +586,11 @@
default:
throw new InvalidOperationException ("Invalid
state for writing EndElement: " + state);
}
- parentForFirstChild = -1;
+ parentStackIndex--;
if (nodes [nodeIndex].NodeType ==
XPathNodeType.Element) {
if (!full)
nodes [nodeIndex].IsEmptyElement = true;
- }
-
- writerDepth--;
+ }
}
public override void WriteStartAttribute (string prefix, string
localName, string ns)
@@ -622,15 +607,15 @@
private void ProcessNamespace (string prefix, string ns)
{
+ int nextTmp = hasLocalNs ? nsIndex : nodes
[nodeIndex].FirstNamespace;
+
nsIndex++;
- int nextTmp = lastNsIndexInCurrent == 0 ? nodes
[nodeIndex].FirstNamespace : lastNsIndexInCurrent;
-
this.AddNsNode (nodeIndex,
prefix,
ns,
nextTmp);
- lastNsIndexInCurrent = nsIndex;
+ hasLocalNs = true;
openNamespace = true;
}
@@ -645,10 +630,10 @@
value,
0,
0);
- if (firstAttributeIndex == 0)
- firstAttributeIndex = attributeIndex;
- else
+ if (hasAttributes)
attributes [attributeIndex - 1].NextAttribute =
attributeIndex;
+ else
+ hasAttributes = true;
}
public override void WriteEndAttribute ()
Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathNode2.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathNode2.cs 2005-03-15
04:34:36 UTC (rev 41823)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathNode2.cs 2005-03-15
05:43:56 UTC (rev 41824)
@@ -52,7 +52,6 @@
public int NextSibling;
public int FirstAttribute;
public int FirstNamespace;
- public int Depth;
public XPathNodeType NodeType;
public int BaseURI;
public bool IsEmptyElement;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches