Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / Dom / DomNameTable.cs / 1305376 / DomNameTable.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Xml.Schema; namespace System.Xml { internal class DomNameTable { XmlName[] entries; int count; int mask; XmlDocument ownerDocument; XmlNameTable nameTable; const int InitialSize = 64; // must be a power of two public DomNameTable( XmlDocument document ) { ownerDocument = document; nameTable = document.NameTable; entries = new XmlName[InitialSize]; mask = InitialSize - 1; Debug.Assert( ( entries.Length & mask ) == 0 ); // entries.Length must be a power of two } public XmlName GetName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName e = entries[hashCode & mask]; e != null; e = e.next) { if (e.HashCode == hashCode && ((object)e.LocalName == (object)localName || e.LocalName.Equals(localName)) && ((object)e.Prefix == (object)prefix || e.Prefix.Equals(prefix)) && ((object)e.NamespaceURI == (object)ns || e.NamespaceURI.Equals(ns)) && e.Equals(schemaInfo)) { return e; } } return null; } public XmlName AddName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName e = entries[hashCode & mask]; e != null; e = e.next) { if (e.HashCode == hashCode && ((object)e.LocalName == (object)localName || e.LocalName.Equals(localName)) && ((object)e.Prefix == (object)prefix || e.Prefix.Equals(prefix)) && ((object)e.NamespaceURI == (object)ns || e.NamespaceURI.Equals(ns)) && e.Equals(schemaInfo)) { return e; } } prefix = nameTable.Add(prefix); localName = nameTable.Add(localName); ns = nameTable.Add(ns); int index = hashCode & mask; XmlName name = XmlName.Create(prefix, localName, ns, hashCode, ownerDocument, entries[index], schemaInfo); entries[index] = name; if (count++ == mask) { Grow(); } return name; } private void Grow() { int newMask = mask * 2 + 1; XmlName[] oldEntries = entries; XmlName[] newEntries = new XmlName[newMask+1]; // use oldEntries.Length to eliminate the rangecheck for ( int i = 0; i < oldEntries.Length; i++ ) { XmlName name = oldEntries[i]; while ( name != null ) { int newIndex = name.HashCode & newMask; XmlName tmp = name.next; name.next = newEntries[newIndex]; newEntries[newIndex] = name; name = tmp; } } entries = newEntries; mask = newMask; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Xml.Schema; namespace System.Xml { internal class DomNameTable { XmlName[] entries; int count; int mask; XmlDocument ownerDocument; XmlNameTable nameTable; const int InitialSize = 64; // must be a power of two public DomNameTable( XmlDocument document ) { ownerDocument = document; nameTable = document.NameTable; entries = new XmlName[InitialSize]; mask = InitialSize - 1; Debug.Assert( ( entries.Length & mask ) == 0 ); // entries.Length must be a power of two } public XmlName GetName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName e = entries[hashCode & mask]; e != null; e = e.next) { if (e.HashCode == hashCode && ((object)e.LocalName == (object)localName || e.LocalName.Equals(localName)) && ((object)e.Prefix == (object)prefix || e.Prefix.Equals(prefix)) && ((object)e.NamespaceURI == (object)ns || e.NamespaceURI.Equals(ns)) && e.Equals(schemaInfo)) { return e; } } return null; } public XmlName AddName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName e = entries[hashCode & mask]; e != null; e = e.next) { if (e.HashCode == hashCode && ((object)e.LocalName == (object)localName || e.LocalName.Equals(localName)) && ((object)e.Prefix == (object)prefix || e.Prefix.Equals(prefix)) && ((object)e.NamespaceURI == (object)ns || e.NamespaceURI.Equals(ns)) && e.Equals(schemaInfo)) { return e; } } prefix = nameTable.Add(prefix); localName = nameTable.Add(localName); ns = nameTable.Add(ns); int index = hashCode & mask; XmlName name = XmlName.Create(prefix, localName, ns, hashCode, ownerDocument, entries[index], schemaInfo); entries[index] = name; if (count++ == mask) { Grow(); } return name; } private void Grow() { int newMask = mask * 2 + 1; XmlName[] oldEntries = entries; XmlName[] newEntries = new XmlName[newMask+1]; // use oldEntries.Length to eliminate the rangecheck for ( int i = 0; i < oldEntries.Length; i++ ) { XmlName name = oldEntries[i]; while ( name != null ) { int newIndex = name.HashCode & newMask; XmlName tmp = name.next; name.next = newEntries[newIndex]; newEntries[newIndex] = name; name = tmp; } } entries = newEntries; mask = newMask; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WeakEventTable.cs
- ExpressionVisitor.cs
- IgnoreDeviceFilterElement.cs
- ResXResourceWriter.cs
- FolderBrowserDialog.cs
- ResourceContainer.cs
- ProtocolsSection.cs
- PerformanceCounter.cs
- QilPatternFactory.cs
- CustomDictionarySources.cs
- FontEmbeddingManager.cs
- UnsafeNativeMethods.cs
- Block.cs
- DataGridColumnsPage.cs
- WebResourceUtil.cs
- PseudoWebRequest.cs
- XmlSerializationGeneratedCode.cs
- AppSecurityManager.cs
- TextServicesDisplayAttributePropertyRanges.cs
- XPathSelfQuery.cs
- SessionParameter.cs
- Merger.cs
- IsolatedStorageFile.cs
- ProtocolsConfiguration.cs
- ObjectSet.cs
- TokenBasedSetEnumerator.cs
- RootProfilePropertySettingsCollection.cs
- CompositionTarget.cs
- StoreItemCollection.cs
- TransactionFilter.cs
- MultidimensionalArrayItemReference.cs
- OleDbReferenceCollection.cs
- MetadataItemCollectionFactory.cs
- ScopelessEnumAttribute.cs
- DriveInfo.cs
- XmlConvert.cs
- Variant.cs
- LogManagementAsyncResult.cs
- ServiceNotStartedException.cs
- ThumbAutomationPeer.cs
- MessageQueueCriteria.cs
- FunctionUpdateCommand.cs
- UIElementParagraph.cs
- PolicyChain.cs
- Security.cs
- Clipboard.cs
- SpeakProgressEventArgs.cs
- MeasureItemEvent.cs
- TreeViewHitTestInfo.cs
- RNGCryptoServiceProvider.cs
- XmlCharCheckingWriter.cs
- XmlTextReaderImpl.cs
- FieldBuilder.cs
- SafeNativeMethodsCLR.cs
- HtmlValidationSummaryAdapter.cs
- LinkButton.cs
- NotifyParentPropertyAttribute.cs
- PropertyRef.cs
- DataGridColumnHeaderCollection.cs
- DesignerResources.cs
- WorkItem.cs
- MessageQueueConverter.cs
- SQLDouble.cs
- PageCatalogPart.cs
- XPathAxisIterator.cs
- WindowsPrincipal.cs
- ListViewAutomationPeer.cs
- ZipIOLocalFileDataDescriptor.cs
- PrincipalPermission.cs
- PointCollection.cs
- SessionStateSection.cs
- WmfPlaceableFileHeader.cs
- ClientOptions.cs
- EntryIndex.cs
- MSAANativeProvider.cs
- LZCodec.cs
- SparseMemoryStream.cs
- FontDifferentiator.cs
- PrimitiveCodeDomSerializer.cs
- TableHeaderCell.cs
- HttpApplicationFactory.cs
- XPathBinder.cs
- WindowVisualStateTracker.cs
- DataRowExtensions.cs
- FragmentNavigationEventArgs.cs
- ConnectionStringsSection.cs
- DeliveryRequirementsAttribute.cs
- KeyPressEvent.cs
- SplineKeyFrames.cs
- ParamArrayAttribute.cs
- ImageSourceValueSerializer.cs
- DataGridViewSelectedRowCollection.cs
- InkPresenter.cs
- BufferAllocator.cs
- AmbiguousMatchException.cs
- Util.cs
- _ListenerAsyncResult.cs
- ClientScriptManager.cs
- SoapInteropTypes.cs
- SqlParameterCollection.cs