Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / SimpleBitVector32.cs / 1305376 / SimpleBitVector32.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Util { using System; // // This is a cut down copy of System.Collections.Specialized.BitVector32. The // reason this is here is because it is used rather intensively by Control and // WebControl. As a result, being able to inline this operations results in a // measurable performance gain, at the expense of some maintainability. // [Serializable] internal struct SimpleBitVector32 { private int data; internal SimpleBitVector32(int data) { this.data = data; } internal int IntegerValue { get { return data; } set { data = value; } } internal bool this[int bit] { get { return (data & bit) == bit; } set { int _data = data; if(value) { data = _data | bit; } else { data = _data & ~bit; } } } // Stores and retrieves a positive integer in the bit vector. The "mask" parameter selects the bits // to use in the vector, and the "offset" parameter is the index of the rightmost bit in the // mask. The offset could be calculated from the mask, but is passed in as a separate constant // for improved performance. NOTE: Because the data field is a signed integer, only 31 of the 32 // available bits may be used. // Example: To store a 4-bit integer in bits 4-7, use mask=0x000000F0 and offset=4. internal int this[int mask, int offset] { get { #if DEBUG VerifyMaskAndOffset(mask, offset); #endif return ((data & mask) >> offset); } set { #if DEBUG VerifyMaskAndOffset(mask, offset); #endif Debug.Assert(value >= 0, "Value must be non-negative."); Debug.Assert(((value << offset) & ~mask) == 0, "Value must fit within the mask."); data = (data & ~mask) | (value << offset); } } #if DEBUG private void VerifyMaskAndOffset(int mask, int offset) { Debug.Assert(mask > 0, "Mask must be nonempty and non-negative."); // Offset must be between 0 and 30 inclusive, since only 31 bits are available and at least one bit must be used. Debug.Assert(offset >= 0 && offset <= 30, "Offset must be between 0 and 30 inclusive."); Debug.Assert((mask & ((1 << offset) - 1)) == 0, "All mask bits to the right of the offset index must be zero."); Debug.Assert(((mask >> offset) & 1) == 1, "The mask bit at the offset index must be one."); } #endif internal void Set(int bit) { data |= bit; } internal void Clear(int bit) { data &= ~bit; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Util { using System; // // This is a cut down copy of System.Collections.Specialized.BitVector32. The // reason this is here is because it is used rather intensively by Control and // WebControl. As a result, being able to inline this operations results in a // measurable performance gain, at the expense of some maintainability. // [Serializable] internal struct SimpleBitVector32 { private int data; internal SimpleBitVector32(int data) { this.data = data; } internal int IntegerValue { get { return data; } set { data = value; } } internal bool this[int bit] { get { return (data & bit) == bit; } set { int _data = data; if(value) { data = _data | bit; } else { data = _data & ~bit; } } } // Stores and retrieves a positive integer in the bit vector. The "mask" parameter selects the bits // to use in the vector, and the "offset" parameter is the index of the rightmost bit in the // mask. The offset could be calculated from the mask, but is passed in as a separate constant // for improved performance. NOTE: Because the data field is a signed integer, only 31 of the 32 // available bits may be used. // Example: To store a 4-bit integer in bits 4-7, use mask=0x000000F0 and offset=4. internal int this[int mask, int offset] { get { #if DEBUG VerifyMaskAndOffset(mask, offset); #endif return ((data & mask) >> offset); } set { #if DEBUG VerifyMaskAndOffset(mask, offset); #endif Debug.Assert(value >= 0, "Value must be non-negative."); Debug.Assert(((value << offset) & ~mask) == 0, "Value must fit within the mask."); data = (data & ~mask) | (value << offset); } } #if DEBUG private void VerifyMaskAndOffset(int mask, int offset) { Debug.Assert(mask > 0, "Mask must be nonempty and non-negative."); // Offset must be between 0 and 30 inclusive, since only 31 bits are available and at least one bit must be used. Debug.Assert(offset >= 0 && offset <= 30, "Offset must be between 0 and 30 inclusive."); Debug.Assert((mask & ((1 << offset) - 1)) == 0, "All mask bits to the right of the offset index must be zero."); Debug.Assert(((mask >> offset) & 1) == 1, "The mask bit at the offset index must be one."); } #endif internal void Set(int bit) { data |= bit; } internal void Clear(int bit) { data &= ~bit; } } } // 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
- GridViewHeaderRowPresenter.cs
- QueryableDataSourceHelper.cs
- Speller.cs
- DataMisalignedException.cs
- AppDomainAttributes.cs
- XmlElement.cs
- AppModelKnownContentFactory.cs
- PropertyManager.cs
- EdmProviderManifest.cs
- WithParamAction.cs
- Convert.cs
- followingsibling.cs
- WorkflowInstance.cs
- NotifyParentPropertyAttribute.cs
- WebPartHeaderCloseVerb.cs
- DataSourceSelectArguments.cs
- GuidelineSet.cs
- ItemType.cs
- DataKey.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- PinnedBufferMemoryStream.cs
- WriteTimeStream.cs
- EdmEntityTypeAttribute.cs
- TextSimpleMarkerProperties.cs
- SQLBoolean.cs
- IsolatedStoragePermission.cs
- LowerCaseStringConverter.cs
- Events.cs
- ClientScriptManagerWrapper.cs
- ReadOnlyDictionary.cs
- SerializationInfoEnumerator.cs
- BinarySerializer.cs
- DesignTimeVisibleAttribute.cs
- SessionEndedEventArgs.cs
- SqlUnionizer.cs
- SessionPageStatePersister.cs
- CreateUserWizardStep.cs
- LayoutEngine.cs
- NonClientArea.cs
- _AutoWebProxyScriptWrapper.cs
- AsyncSerializedWorker.cs
- StylusOverProperty.cs
- XmlReaderSettings.cs
- TargetControlTypeCache.cs
- ChangeConflicts.cs
- _NTAuthentication.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- CapabilitiesAssignment.cs
- UrlPath.cs
- HuffModule.cs
- ProgressBar.cs
- loginstatus.cs
- SiteOfOriginContainer.cs
- Base64Encoding.cs
- BindingExpression.cs
- LocalizationComments.cs
- HtmlInputImage.cs
- LocalServiceSecuritySettings.cs
- ContentFileHelper.cs
- RangeBaseAutomationPeer.cs
- ProcessModelInfo.cs
- UrlAuthFailedErrorFormatter.cs
- XomlCompilerParameters.cs
- MSAANativeProvider.cs
- XamlFrame.cs
- DataGridViewIntLinkedList.cs
- QueryAccessibilityHelpEvent.cs
- Size.cs
- SafeHandles.cs
- ListDependantCardsRequest.cs
- CatalogZoneBase.cs
- CellQuery.cs
- SmtpSection.cs
- DefaultProxySection.cs
- XmlDataDocument.cs
- RequestSecurityTokenResponse.cs
- TextLineResult.cs
- SmiContextFactory.cs
- OwnerDrawPropertyBag.cs
- loginstatus.cs
- KeysConverter.cs
- uribuilder.cs
- HttpCookiesSection.cs
- XmlILOptimizerVisitor.cs
- PropertyTabChangedEvent.cs
- XmlReaderSettings.cs
- UIPropertyMetadata.cs
- WindowsImpersonationContext.cs
- SmiXetterAccessMap.cs
- CrossAppDomainChannel.cs
- DataObjectSettingDataEventArgs.cs
- MergeFilterQuery.cs
- WpfKnownMember.cs
- ScrollChangedEventArgs.cs
- PlatformCulture.cs
- ConfigurationStrings.cs
- XmlProcessingInstruction.cs
- InternalResources.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- DataGridViewCellPaintingEventArgs.cs