Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ConstraintEnumerator.cs
- Input.cs
- PriorityRange.cs
- AttachmentService.cs
- GatewayIPAddressInformationCollection.cs
- ResourceContainer.cs
- OrderedDictionary.cs
- SqlCacheDependencySection.cs
- Rect.cs
- DataGridViewCellPaintingEventArgs.cs
- FormViewModeEventArgs.cs
- QueryCursorEventArgs.cs
- MetadataException.cs
- TTSEngineTypes.cs
- FacetValueContainer.cs
- EntityFrameworkVersions.cs
- EditorAttribute.cs
- UpdatePanelControlTrigger.cs
- BuildProvider.cs
- PixelFormats.cs
- DllNotFoundException.cs
- RadioButtonRenderer.cs
- BrowsableAttribute.cs
- PropertyEmitterBase.cs
- BreakRecordTable.cs
- HtmlGenericControl.cs
- NavigationEventArgs.cs
- UpdateTracker.cs
- BrushMappingModeValidation.cs
- UInt32.cs
- ImportFileRequest.cs
- SQLByteStorage.cs
- Vector3DIndependentAnimationStorage.cs
- EventProviderBase.cs
- CompilationRelaxations.cs
- FontInfo.cs
- PingReply.cs
- RequestCachePolicy.cs
- HttpConfigurationSystem.cs
- OptimalBreakSession.cs
- SemanticResultKey.cs
- HttpRuntime.cs
- PropertyChangingEventArgs.cs
- tabpagecollectioneditor.cs
- PrinterResolution.cs
- WebEvents.cs
- TextDecoration.cs
- BamlCollectionHolder.cs
- Wizard.cs
- MemberDomainMap.cs
- SettingsSavedEventArgs.cs
- VirtualPathProvider.cs
- ImageList.cs
- Attributes.cs
- PrintDialog.cs
- FragmentQueryKB.cs
- HwndHostAutomationPeer.cs
- GACMembershipCondition.cs
- ImageMapEventArgs.cs
- BitmapCache.cs
- InvalidateEvent.cs
- HtmlControl.cs
- CmsUtils.cs
- PropertyInformation.cs
- ServicePointManager.cs
- InvokeMethodActivityDesigner.cs
- XmlHierarchyData.cs
- PrimitiveSchema.cs
- RTLAwareMessageBox.cs
- TextServicesContext.cs
- StrongNameKeyPair.cs
- ControlValuePropertyAttribute.cs
- UnmanagedMarshal.cs
- validation.cs
- SmtpNegotiateAuthenticationModule.cs
- ZoneIdentityPermission.cs
- Point3DValueSerializer.cs
- ExpandSegment.cs
- EDesignUtil.cs
- XmlTextWriter.cs
- HtmlGenericControl.cs
- NamespaceEmitter.cs
- XmlRawWriter.cs
- GestureRecognizer.cs
- FileSystemWatcher.cs
- ListViewInsertEventArgs.cs
- UIElement3DAutomationPeer.cs
- TypeConverterHelper.cs
- MissingFieldException.cs
- CounterCreationData.cs
- XmlComplianceUtil.cs
- ContentElement.cs
- LookupNode.cs
- HtmlHistory.cs
- StringFormat.cs
- XmlAutoDetectWriter.cs
- StructuralObject.cs
- xamlnodes.cs
- TableColumnCollectionInternal.cs
- EasingKeyFrames.cs