The Labs \ Source Viewer \ SSCLI \ System.Configuration \ SimpleBitVector32

  1. //------------------------------------------------------------------------------
  2. // <copyright file="SimpleBitVector32.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Configuration
  16. {
  17.     using System;
  18.    
  19.     //
  20.     // This is a cut down copy of System.Collections.Specialized.BitVector32. The
  21.     // reason this is here is because it is used rather intensively by Control and
  22.     // WebControl. As a result, being able to inline this operations results in a
  23.     // measurable performance gain, at the expense of some maintainability.
  24.     //
  25.     [Serializable()]
  26.     internal struct SimpleBitVector32
  27.     {
  28.         private int data;
  29.        
  30.         internal SimpleBitVector32(int data)
  31.         {
  32.             this.data = data;
  33.         }
  34.        
  35.         internal int Data {
  36.             get { return data; }
  37.         }
  38.        
  39.         internal bool this[int bit]
  40.         {
  41.             get { return (data & bit) == bit; }
  42.             set {
  43.                 int _data = data;
  44.                 if (value) {
  45.                     data = _data | bit;
  46.                 }
  47.                 else {
  48.                     data = _data & ~bit;
  49.                 }
  50.             }
  51.         }
  52.        
  53.     }
  54. }

Developer Fusion