2003-09-20 Ben Maurer <bmaurer@users.sourceforge.net>
authorBen Maurer <benm@mono-cvs.ximian.com>
Sat, 20 Sep 2003 20:30:16 +0000 (20:30 -0000)
committerBen Maurer <benm@mono-cvs.ximian.com>
Sat, 20 Sep 2003 20:30:16 +0000 (20:30 -0000)
* Attribute.cs: Change to struct. Remove QName class.
* GenericOutputter.cs: use an Attribute [] rather than an
ArrayList. Allows us not to allocate Attributes, which is great
for speed. Roll our own allocation.

svn path=/trunk/mcs/; revision=18220

mcs/class/System.XML/Mono.Xml.Xsl/Attribute.cs
mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
mcs/class/System.XML/Mono.Xml.Xsl/GenericOutputter.cs

index 8fa3011bad86ba478d1c855a55b986e904558830..4222225de376a3932af451ca7c18f1d11b038064 100644 (file)
@@ -14,15 +14,18 @@ namespace Mono.Xml.Xsl {
        /// <summary>
        /// XML attribute.
        /// </summary>
-       public class Attribute {
-           public string Prefix;
-           public XmlQualifiedName QName;
-           public string Value;
+       public struct Attribute {
+               public string Prefix;
+               public string Namespace;
+               public string LocalName;
+               public string Value;
            
-               public Attribute(string prefix, XmlQualifiedName qName, string value){
-                   Prefix = prefix;
-                   QName = qName;
-                   Value = value;
+               public Attribute (string prefix, string namespaceUri, string localName, string value)
+               {
+                       this.Prefix = prefix;
+                       this.Namespace = namespaceUri;
+                       this.LocalName = localName;
+                       this.Value = value;
                }
        }
 }
index 70e52d131809edfc2ffcb54db930130ccb8a2dd5..2bf684144feec37188506a1697375643b960b16d 100644 (file)
@@ -1,3 +1,10 @@
+2003-09-20 Ben Maurer  <bmaurer@users.sourceforge.net>
+
+       * Attribute.cs: Change to struct. Remove QName class.
+       * GenericOutputter.cs: use an Attribute [] rather than an
+       ArrayList. Allows us not to allocate Attributes, which is great
+       for speed. Roll our own allocation.
+
 2003-09-20 Ben Maurer  <bmaurer@users.sourceforge.net>
 
        * Compiler.cs: add GetNsm to main class as well.
index 1b889207783fe8748f8693ce262905bdfd5cec1d..df90154ae0c877f746212018b37cf611cac5e4fd 100644 (file)
@@ -31,7 +31,8 @@ namespace Mono.Xml.Xsl
                // Collection of pending attributes. TODO: Can we make adding an attribute
                // O(1)? I'm not sure it is that important (this would only really make a difference
                // if elements had like 10 attributes, which is very rare).
-               ArrayList pendingAttributes = new ArrayList ();
+               Attribute [] pendingAttributes = new Attribute [10];
+               int pendingAttributesPos = 0;
                //Namespace manager. Subject to optimization.
                private XmlNamespaceManager _nsManager;
                //Name table
@@ -86,8 +87,9 @@ namespace Mono.Xml.Xsl
                                //namespaces to WriteStartElement
                                _nsManager.PushScope ();
                                //Emit pending attributes
-                               foreach (Attribute attr in pendingAttributes) {
-                                       _emitter.WriteAttributeString (attr.Prefix, attr.QName.Name, attr.QName.Namespace, attr.Value);
+                               for (int i = 0; i < pendingAttributesPos; i++) {
+                                       Attribute attr = pendingAttributes [i];
+                                       _emitter.WriteAttributeString (attr.Prefix, attr.LocalName, attr.Namespace, attr.Value);
                                }       
                                //Attributes flushed, state is Content now                              
                                _state = WriteState.Content;
@@ -120,7 +122,7 @@ namespace Mono.Xml.Xsl
                        CheckState ();
                        _emitter.WriteStartElement (prefix, localName, nsURI);
                        _state = WriteState.Element;                                            
-                       pendingAttributes.Clear ();
+                       pendingAttributesPos = 0;
                }
 
                public override void WriteEndElement ()
@@ -135,10 +137,10 @@ namespace Mono.Xml.Xsl
                public override void WriteAttributeString (string prefix, string localName, string nsURI, string value)
                {                                                                               
                        //Put attribute to pending attributes collection, replacing namesake one
-                       XmlQualifiedName qName = new XmlQualifiedName (localName, nsURI);
-                       
-                       foreach (Attribute attr in pendingAttributes) {
-                               if (attr.QName == qName) {
+                       for (int i = 0; i < pendingAttributesPos; i++) {
+                               Attribute attr = pendingAttributes [i];
+                               
+                               if (attr.LocalName == localName && attr.Namespace == nsURI) {
                                        attr.Value = value;
                                        //Keep prefix (e.g. when literal attribute is overriden by xsl:attribute)
                                        if (attr.Prefix == String.Empty && prefix != String.Empty)
@@ -148,7 +150,17 @@ namespace Mono.Xml.Xsl
                                }
                        }
                        
-                       pendingAttributes.Add (new Attribute (prefix, qName, value));   
+                       if (pendingAttributesPos == pendingAttributes.Length) {
+                               Attribute [] old = pendingAttributes;
+                               pendingAttributes = new Attribute [pendingAttributesPos * 2 + 1];
+                               if (pendingAttributesPos > 0)
+                                       Array.Copy (old, 0, pendingAttributes, 0, pendingAttributesPos);
+                       }
+                       pendingAttributes [pendingAttributesPos].Prefix = prefix;
+                       pendingAttributes [pendingAttributesPos].Namespace = nsURI;
+                       pendingAttributes [pendingAttributesPos].LocalName = localName;
+                       pendingAttributes [pendingAttributesPos].Value = value;
+                       pendingAttributesPos++;
                }
 
                public override void WriteNamespaceDecl (string prefix, string nsUri)