Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Xml / System / Xml / Dom / DomNameTable.cs / 1 / 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
- DataServiceConfiguration.cs
- GroupStyle.cs
- Image.cs
- DesignerDataRelationship.cs
- LinqDataSourceInsertEventArgs.cs
- ScopelessEnumAttribute.cs
- StateManagedCollection.cs
- PieceNameHelper.cs
- IODescriptionAttribute.cs
- SqlCrossApplyToCrossJoin.cs
- TextBreakpoint.cs
- ButtonColumn.cs
- EntityException.cs
- FeatureManager.cs
- SecuritySessionSecurityTokenAuthenticator.cs
- PenContexts.cs
- ResizeGrip.cs
- ParamArrayAttribute.cs
- DrawingCollection.cs
- EditingCommands.cs
- DataGridViewIntLinkedList.cs
- EqualityComparer.cs
- BaseValidator.cs
- HeaderUtility.cs
- PingOptions.cs
- CriticalFinalizerObject.cs
- WebPartEditVerb.cs
- SynchronizedDispatch.cs
- ChtmlTextWriter.cs
- EmptyReadOnlyDictionaryInternal.cs
- SettingsBase.cs
- SoapReflectionImporter.cs
- ClientProtocol.cs
- VisualTreeHelper.cs
- WindowsListViewGroupSubsetLink.cs
- StringBuilder.cs
- CharEntityEncoderFallback.cs
- SortFieldComparer.cs
- SqlInternalConnection.cs
- ObjectCacheHost.cs
- XPathAncestorQuery.cs
- TagPrefixInfo.cs
- WebPartTransformerAttribute.cs
- CodeTypeDeclaration.cs
- PersistenceProviderBehavior.cs
- RemotingAttributes.cs
- StickyNote.cs
- EventItfInfo.cs
- StringConverter.cs
- DockingAttribute.cs
- TypeConvertions.cs
- ClientSponsor.cs
- ButtonBaseAdapter.cs
- PrintDialog.cs
- AssemblyCollection.cs
- ExpandCollapseProviderWrapper.cs
- XamlReaderHelper.cs
- CodeDirectoryCompiler.cs
- DocumentPageViewAutomationPeer.cs
- RouteUrlExpressionBuilder.cs
- DirectoryInfo.cs
- XmlChildEnumerator.cs
- Int16AnimationBase.cs
- PrivilegeNotHeldException.cs
- ConfigXmlAttribute.cs
- XmlReader.cs
- PngBitmapEncoder.cs
- SchemaConstraints.cs
- WizardForm.cs
- QueryExecutionOption.cs
- PersonalizationAdministration.cs
- ResourceReferenceKeyNotFoundException.cs
- DateBoldEvent.cs
- ApplicationBuildProvider.cs
- PersonalizationProvider.cs
- ResXBuildProvider.cs
- OleServicesContext.cs
- EditingCommands.cs
- OletxVolatileEnlistment.cs
- SessionStateSection.cs
- FilterFactory.cs
- Mutex.cs
- IDictionary.cs
- ManagementQuery.cs
- DataQuery.cs
- ListDictionary.cs
- DBNull.cs
- SingleAnimation.cs
- CalendarAutomationPeer.cs
- DataServiceRequest.cs
- SendMessageRecord.cs
- GridViewCommandEventArgs.cs
- ThaiBuddhistCalendar.cs
- TransformerInfo.cs
- DiscoveryOperationContext.cs
- ColumnMapVisitor.cs
- SqlRowUpdatingEvent.cs
- CodeSubDirectoriesCollection.cs
- TextServicesManager.cs
- GeometryGroup.cs