2 // System.Xml.XmlNameEntryCache.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2005 Novell, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
36 internal class XmlNameEntryCache
38 Hashtable table = new Hashtable ();
39 XmlNameTable nameTable;
40 XmlNameEntry dummy = new XmlNameEntry (String.Empty, String.Empty, String.Empty);
43 public XmlNameEntryCache (XmlNameTable nameTable)
45 this.nameTable = nameTable;
48 public string GetAtomizedPrefixedName (string prefix, string local)
50 if (prefix == null || prefix.Length == 0)
53 if (cacheBuffer == null)
54 cacheBuffer = new char [20];
55 if (cacheBuffer.Length < prefix.Length + local.Length + 1)
56 cacheBuffer = new char [Math.Max (
57 prefix.Length + local.Length + 1,
58 cacheBuffer.Length << 1)];
59 prefix.CopyTo (0, cacheBuffer, 0, prefix.Length);
60 cacheBuffer [prefix.Length] = ':';
61 local.CopyTo (0, cacheBuffer, prefix.Length + 1, local.Length);
62 return nameTable.Add (cacheBuffer, 0, prefix.Length + local.Length + 1);
65 public XmlNameEntry Add (string prefix, string local, string ns,
69 prefix = nameTable.Add (prefix);
70 local = nameTable.Add (local);
71 ns = nameTable.Add (ns);
73 XmlNameEntry e = GetInternal (prefix, local, ns, true);
75 e = new XmlNameEntry (prefix, local, ns);
81 public XmlNameEntry Get (string prefix, string local, string ns,
84 XmlNameEntry e = GetInternal (prefix, local, ns, atomic);
88 private XmlNameEntry GetInternal (string prefix, string local,
89 string ns, bool atomic)
92 if (nameTable.Get (prefix) == null ||
93 nameTable.Get (local) == null ||
94 nameTable.Get (ns) == null)
97 dummy.Update (prefix, local, ns);
99 return table [dummy] as XmlNameEntry;