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
- _UriSyntax.cs
- NetNamedPipeBindingElement.cs
- X500Name.cs
- SQLMoney.cs
- ItemDragEvent.cs
- RelativeSource.cs
- _emptywebproxy.cs
- SessionState.cs
- Substitution.cs
- ImageKeyConverter.cs
- ApplicationFileParser.cs
- ClientCultureInfo.cs
- BrushValueSerializer.cs
- OptimalTextSource.cs
- DecimalConstantAttribute.cs
- ToolBarTray.cs
- FollowerQueueCreator.cs
- InvokeBase.cs
- ResponseStream.cs
- SqlNode.cs
- InvalidStoreProtectionKeyException.cs
- TagElement.cs
- TextDecorationUnitValidation.cs
- XmlEntityReference.cs
- FontStretchConverter.cs
- SpecularMaterial.cs
- ObservableDictionary.cs
- KeyValuePair.cs
- UnicodeEncoding.cs
- CursorConverter.cs
- DetailsViewCommandEventArgs.cs
- DataGridViewCellParsingEventArgs.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- ProviderBase.cs
- SystemException.cs
- XmlAnyElementAttributes.cs
- _NtlmClient.cs
- MediaTimeline.cs
- PagePropertiesChangingEventArgs.cs
- ACL.cs
- EntryWrittenEventArgs.cs
- mediaclock.cs
- RubberbandSelector.cs
- X509CertificateTokenFactoryCredential.cs
- CodeGenerator.cs
- GenericPrincipal.cs
- BindMarkupExtensionSerializer.cs
- TextSpanModifier.cs
- SmiEventSink_Default.cs
- BooleanToVisibilityConverter.cs
- ShimAsPublicXamlType.cs
- ItemTypeToolStripMenuItem.cs
- ScriptBehaviorDescriptor.cs
- CategoriesDocument.cs
- XamlDesignerSerializationManager.cs
- ExtractedStateEntry.cs
- StreamWithDictionary.cs
- BuilderInfo.cs
- DataKeyCollection.cs
- ComEventsMethod.cs
- AddInServer.cs
- RewritingPass.cs
- ItemsPresenter.cs
- DbQueryCommandTree.cs
- CodePageEncoding.cs
- Package.cs
- ReferenceEqualityComparer.cs
- GenericFlowSwitchHelper.cs
- RemotingServices.cs
- EventDescriptor.cs
- ApplicationHost.cs
- NominalTypeEliminator.cs
- FormView.cs
- Pair.cs
- IPCCacheManager.cs
- ProfilePropertyNameValidator.cs
- HtmlShim.cs
- FixedTextContainer.cs
- NativeActivityContext.cs
- MetadataUtilsSmi.cs
- PasswordTextNavigator.cs
- Module.cs
- InputMethodStateTypeInfo.cs
- CodeDelegateInvokeExpression.cs
- ToolStripHighContrastRenderer.cs
- PtsContext.cs
- SubclassTypeValidator.cs
- ColumnWidthChangedEvent.cs
- ConfigXmlReader.cs
- DecoratedNameAttribute.cs
- ControlType.cs
- MenuItemStyle.cs
- PageBreakRecord.cs
- DataBinder.cs
- TableAdapterManagerNameHandler.cs
- StreamReader.cs
- XdrBuilder.cs
- IUnknownConstantAttribute.cs
- dtdvalidator.cs
- RefExpr.cs