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
}
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;
{
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;
}
}
// 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 ()
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)