Changeset 2571


Ignore:
Timestamp:
3/22/2012 2:58:33 AM (3 years ago)
Author:
lowjoel
Message:

Use our MemoryXor? function to invert the pool, instead of writing another loop. Performance for this code is about 10% faster than the unsafe loop, on average, on x64.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.Manager/EntropyPoller.cs

    r2570 r2571  
    4646        public EntropyPoller() 
    4747        { 
    48             //Create the pool. 
     48            //Create the pool and its complement. 
    4949            Pool = new byte[sizeof(uint) << 7]; 
     50            PoolInvert = new byte[Pool.Length]; 
     51            for (uint i = 0, j = (uint)PoolInvert.Length; i < j; ++i) 
     52                PoolInvert[i] = byte.MaxValue; 
    5053 
    5154            //Handle the Entropy Source Registered event. 
     
    162165 
    163166        /// <summary> 
    164         /// Inverts the contents of the pool 
     167        /// Inverts the contents of the pool. 
    165168        /// </summary> 
    166169        private void InvertPool() 
    167170        { 
    168171            lock (PoolLock) 
    169                 unsafe 
    170                 { 
    171                     fixed (byte* fPool = Pool) 
    172                     { 
    173                         uint* pPool = (uint*)fPool; 
    174                         uint poolLength = (uint)(Pool.Length / sizeof(uint)); 
    175                         while (poolLength-- != 0) 
    176                             *pPool = (uint)(*pPool++ ^ uint.MaxValue); 
    177                     } 
    178                 } 
     172            { 
     173                MemoryXor(PoolInvert, 0, Pool, 0, Pool.Length); 
     174            } 
    179175        } 
    180176 
     
    323319 
    324320        /// <summary> 
     321        /// A pool, the same size as <see cref="Pool"/>, but containing all bitwise 1's 
     322        /// for XOR for pool inversion 
     323        /// </summary> 
     324        private byte[] PoolInvert; 
     325 
     326        /// <summary> 
    325327        /// The next position where entropy will be added to the pool. 
    326328        /// </summary> 
Note: See TracChangeset for help on using the changeset viewer.