performance hacking
authorBen Maurer <benm@mono-cvs.ximian.com>
Sat, 6 Sep 2003 20:29:44 +0000 (20:29 -0000)
committerBen Maurer <benm@mono-cvs.ximian.com>
Sat, 6 Sep 2003 20:29:44 +0000 (20:29 -0000)
svn path=/trunk/mcs/; revision=17951

mcs/class/System.XML/System.Xml/NameTable.cs
mcs/class/System.XML/System.Xml/XmlQualifiedName.cs

index d4bc31e73c066e89f2214a056f94fb338453f659..52e1bcde202d9db09060bd5234186ec8f557e449 100755 (executable)
@@ -66,11 +66,14 @@ namespace System.Xml {
                
                public override string Add (string key)
                {
-                       if (key == String.Empty) return String.Empty;
+                       if (key == null) throw new ArgumentNullException ("key");
+
+                       int keyLen = key.Length;
+                       if (keyLen == 0) return String.Empty;
                                
                        int h = 0;
                        // This is from the String.Gethash () icall
-                       for (int i = 0; i < key.Length; i++)
+                       for (int i = 0; i < keyLen; i++)
                                h = (h << 5) - h + key [i];
                        
                        // h must be be >= 0
@@ -108,11 +111,14 @@ namespace System.Xml {
                }
                
                public override string Get (string value) {
-                       if (value == String.Empty) return value;
-                       
+                       if (value == null) throw new ArgumentNullException ("value");
+
+                       int valLen = value.Length;
+                       if (valLen == 0) return String.Empty;
+                               
                        int h = 0;
                        // This is from the String.Gethash () icall
-                       for (int i = 0; i < value.Length; i++)
+                       for (int i = 0; i < valLen; i++)
                                h = (h << 5) - h + value [i];
                        // h must be be >= 0
                        h &= 0x7FFFFFFF;
index 838ed82242a41950f71f246357cfe5b146ffe4fc..e61dd0aebde1f30e6285d374e0280a032c34fcbd 100644 (file)
@@ -30,21 +30,20 @@ namespace System.Xml
                {
                        this.name = (name == null) ? "" : name;
                        this.ns = (ns == null) ? "" : ns;
+                       this.hash = name.GetHashCode () ^ ns.GetHashCode ();
                }
 
                // Fields
                public static readonly XmlQualifiedName Empty = new XmlQualifiedName ();                
                private readonly string name;
                private readonly string ns;
+               private readonly int hash;
                
                // Properties
                public bool IsEmpty
                {
                        get {
-                               if ((name == String.Empty) && (ns == String.Empty))
-                                       return true;
-                               else
-                                       return false;
+                               return name.Length == 0 && ns.Length == 0;
                        }
                }
 
@@ -61,18 +60,12 @@ namespace System.Xml
                // Methods
                public override bool Equals (object other)
                {
-                       if(!(other is XmlQualifiedName))
-                               return false;
-
-                       if ((XmlQualifiedName) this == (XmlQualifiedName) other)
-                               return true;
-                       else
-                               return false;
+                       return this == (other as XmlQualifiedName);
                }
 
                public override int GetHashCode () 
                { 
-                       return unchecked (name.GetHashCode () + ns.GetHashCode ());
+                       return hash;
                }
 
                public override string ToString ()
@@ -100,10 +93,7 @@ namespace System.Xml
                        if((Object)a == null || (Object)b == null)
                                return false;
 
-                       if ((a.Name == b.Name) && (a.Namespace == b.Namespace))
-                               return true;
-                       else
-                               return false;
+                       return (a.hash == b.hash) && (a.name == b.name) && (a.ns == b.ns);
                }
 
                public static bool operator != (XmlQualifiedName a, XmlQualifiedName b)