Author: atsushi
Date: 2008-02-11 09:20:23 -0500 (Mon, 11 Feb 2008)
New Revision: 95437
Modified:
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNamespace.cs
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs
Log:
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
* XNamespace.cs : make Get() and GetName() table-based.
* XNamespaceTest.cs : test Get() and GetName().
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2008-02-11
14:20:08 UTC (rev 95436)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2008-02-11
14:20:23 UTC (rev 95437)
@@ -1,5 +1,9 @@
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XNamespace.cs : make Get() and GetName() table-based.
+
+2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* XNodeNavigator.cs : MoveToId() is not supported in this class.
* XElement.cs : allow DTD by default.
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNamespace.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNamespace.cs
2008-02-11 14:20:08 UTC (rev 95436)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNamespace.cs
2008-02-11 14:20:23 UTC (rev 95437)
@@ -35,10 +35,17 @@
{
public sealed class XNamespace
{
- static readonly XNamespace blank = Get (String.Empty);
- static readonly XNamespace xml = Get
("http://www.w3.org/XML/1998/namespace");
- static readonly XNamespace xmlns = Get
("http://www.w3.org/2000/xmlns/");
-
+ static readonly XNamespace blank, xml, xmlns;
+ static Dictionary<string, XNamespace> nstable;
+
+ static XNamespace ()
+ {
+ nstable = new Dictionary<string, XNamespace> ();
+ blank = Get (String.Empty);
+ xml = Get ("http://www.w3.org/XML/1998/namespace");
+ xmlns = Get ("http://www.w3.org/2000/xmlns/");
+ }
+
public static XNamespace None {
get { return blank; }
}
@@ -51,19 +58,34 @@
get { return xmlns; }
}
- [MonoTODO]
public static XNamespace Get (string uri)
{
- return new XNamespace (uri);
+ lock (nstable) {
+ XNamespace ret;
+ if (!nstable.TryGetValue (uri, out ret)) {
+ ret = new XNamespace (uri);
+ nstable [uri] = ret;
+ }
+ return ret;
+ }
}
- [MonoTODO]
public XName GetName (string localName)
{
- return new XName (localName, this);
+ if (table == null)
+ table = new Dictionary<string, XName> ();
+ lock (table) {
+ XName ret;
+ if (!table.TryGetValue (localName, out ret)) {
+ ret = new XName (localName, this);
+ table [localName] = ret;
+ }
+ return ret;
+ }
}
string uri;
+ Dictionary<string, XName> table;
XNamespace (string namespaceName)
{
@@ -78,6 +100,8 @@
public override bool Equals (object other)
{
+ if (Object.ReferenceEquals (this, other))
+ return true;
XNamespace ns = other as XNamespace;
return ns != null && uri == ns.uri;
}
Modified: trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2008-02-11 14:20:08 UTC (rev 95436)
+++ trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2008-02-11 14:20:23 UTC (rev 95437)
@@ -1,5 +1,9 @@
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XNamespaceTest.cs : test Get() and GetName().
+
+2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* XNodeNavigatorTest.cs : test MoveToId() (NotSupportedException,
cannot be enabled yet).
Modified: trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs
2008-02-11 14:20:08 UTC (rev 95436)
+++ trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs
2008-02-11 14:20:23 UTC (rev 95437)
@@ -92,6 +92,25 @@
}
[Test]
+ public void Get2 ()
+ {
+ XNamespace n = XNamespace.Get (String.Empty);
+ Assert.IsTrue (Object.ReferenceEquals (XNamespace.None,
n), "#1");
+ n = XNamespace.Get ("http://www.w3.org/2000/xmlns/");
+ Assert.IsTrue (Object.ReferenceEquals
(XNamespace.Xmlns, n), "#2");
+ Assert.IsTrue (Object.ReferenceEquals (XNamespace.Get
("urn:foo"), XNamespace.Get ("urn:foo")), "#3");
+ }
+
+ [Test]
+ public void GetName ()
+ {
+ XNamespace n = XNamespace.Get ("urn:foo");
+ Assert.IsTrue (Object.ReferenceEquals (n.GetName
("foo"), n.GetName ("foo")), "#1");
+ Assert.IsTrue (n.GetName ("foo") == n.GetName ("foo"),
"#2");
+ Assert.IsFalse (n.GetName ("foo") == n.GetName ("bar"),
"#3");
+ }
+
+ [Test]
public void Predefined ()
{
Assert.AreEqual
("http://www.w3.org/XML/1998/namespace", XNamespace.Xml.NamespaceName, "#1");
@@ -109,16 +128,13 @@
Assert.AreEqual ("http://www.novell.com",
d.NamespaceName, "nsname");
}
-/*
-// there is no Blank anymore
[Test]
public void Equals ()
{
- Assert.IsTrue (XNamespace.Blank.Equals (XNamespace.Get
("")), "#1");
- Assert.IsTrue (XNamespace.Blank == XNamespace.Get (""),
"#2");
- Assert.IsFalse (XNamespace.Blank.Equals (XNamespace.Get
(" ")), "#3");
- Assert.IsFalse (XNamespace.Blank == XNamespace.Get ("
"), "#4");
+ Assert.IsTrue (XNamespace.None.Equals (XNamespace.Get
("")), "#1");
+ Assert.IsTrue (XNamespace.None == XNamespace.Get (""),
"#2");
+ Assert.IsFalse (XNamespace.None.Equals (XNamespace.Get
(" ")), "#3");
+ Assert.IsFalse (XNamespace.None == XNamespace.Get ("
"), "#4");
}
-*/
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches