From 7ec11b91b989c081242279d9516c4b439a328990 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Tue, 8 May 2007 18:42:00 +0000 Subject: [PATCH] Several small optimizations; improved XML comments; added a text file for storing general ideas about the design of Nuclex.Support git-svn-id: file:///srv/devel/repo-conversion/nusu@15 d2e56fa2-650e-0410-a79f-9358c0239efd --- Nuclex.Support (PC).csproj | 6 ++++ Nuclex.Support.txt | 28 +++++++++++++++++++ Source/Collections/RingMemoryStream.cs | 7 ++++- .../TransformingReadOnlyCollection.cs | 2 +- .../Tracking/Internal/ObservedProgression.cs | 6 ++-- Source/Tracking/SetProgression.cs | 18 +++--------- 6 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 Nuclex.Support.txt diff --git a/Nuclex.Support (PC).csproj b/Nuclex.Support (PC).csproj index 517e18a..3987a0c 100644 --- a/Nuclex.Support (PC).csproj +++ b/Nuclex.Support (PC).csproj @@ -182,6 +182,12 @@ WeightedProgressionWrapperCollection + + + false + Nuclex.Support + + diff --git a/Nuclex.Support.txt b/Nuclex.Support.txt new file mode 100644 index 0000000..4e29d84 --- /dev/null +++ b/Nuclex.Support.txt @@ -0,0 +1,28 @@ + #if DEBUG + + /// Generates a new random shuffle table + /// + /// Number of iterations in which to randomize the shuffle table + /// + /// The new random shuffle table + public static byte[] generateShuffleTable(int iterationCount) { + byte[] shuffleTable = new byte[128]; + for(int index = 0; index < 128; ++index) + shuffleTable[index] = index; + + Random rng = new Random(); + + for(int iteration = 0; iteration < iterationCount; ++iteration) { + int firstIndex = rng.Next() % 128; + int secondIndex = rng.Next() % 128; + + byte temp = shuffleTable[firstIndex]; + shuffleTable[firstIndex] = shuffleTable[secondIndex]; + shuffleTable[secondIndex] = temp; + } + + return shuffleTable; + } + + #endif + diff --git a/Source/Collections/RingMemoryStream.cs b/Source/Collections/RingMemoryStream.cs index 11e104f..c89d83d 100644 --- a/Source/Collections/RingMemoryStream.cs +++ b/Source/Collections/RingMemoryStream.cs @@ -4,6 +4,10 @@ using System.IO; namespace Nuclex.Support.Collections { /// Specialized memory stream for ring buffers + /// + /// This ring buffer class is specialized for binary data and tries to achieve + /// optimal efficiency for storing and retrieving chunks of multiple bytes at once. + /// public class RingMemoryStream : Stream { /// Initializes a new ring memory stream @@ -16,7 +20,8 @@ namespace Nuclex.Support.Collections { /// Maximum amount of data that will fit into the ring memory stream /// - /// If the reduced capacity is too small for the ring buffer's current data + /// Thrown if the new capacity is too small for the data already contained + /// in the ring buffer. /// public long Capacity { get { return this.ringBuffer.Length; } diff --git a/Source/Collections/TransformingReadOnlyCollection.cs b/Source/Collections/TransformingReadOnlyCollection.cs index a74e1da..6102569 100644 --- a/Source/Collections/TransformingReadOnlyCollection.cs +++ b/Source/Collections/TransformingReadOnlyCollection.cs @@ -253,7 +253,7 @@ namespace Nuclex.Support.Collections { /// This method is used to transform an item in the wrapped collection into /// the exposed item type whenever the user accesses an item. Expect it to /// be called frequently, because the TransformingReadOnlyCollection does - /// not cache otherwise store the transformed items. + /// not cache or otherwise store the transformed items. /// protected abstract ExposedItemType Transform(ContainedItemType item); diff --git a/Source/Tracking/Internal/ObservedProgression.cs b/Source/Tracking/Internal/ObservedProgression.cs index 2906387..a1dec6d 100644 --- a/Source/Tracking/Internal/ObservedProgression.cs +++ b/Source/Tracking/Internal/ObservedProgression.cs @@ -62,8 +62,10 @@ namespace Nuclex.Support.Tracking { asyncDisconnectEvents(); // We don't need those anymore! - this.progress = 1.0f; - progressUpdateCallback(); + if(this.progress != 1.0f) { + this.progress = 1.0f; + progressUpdateCallback(); + } endedCallback(); } diff --git a/Source/Tracking/SetProgression.cs b/Source/Tracking/SetProgression.cs index bc0f2c9..9fcf90a 100644 --- a/Source/Tracking/SetProgression.cs +++ b/Source/Tracking/SetProgression.cs @@ -14,12 +14,6 @@ namespace Nuclex.Support.Tracking { /// Performs common initialization for the public constructors private SetProgression() { this.childs = new List>(); - - this.asyncProgressUpdatedDelegate = - new ObservedProgression.ReportDelegate(asyncProgressUpdated); - - this.asyncEndedDelegate = - new ObservedProgression.ReportDelegate(asyncEnded); } /// Initializes a new set progression @@ -36,7 +30,8 @@ namespace Nuclex.Support.Tracking { this.childs.Add( new ObservedProgression( new WeightedProgression(progression), - this.asyncProgressUpdatedDelegate, this.asyncEndedDelegate + new ObservedProgression.ReportDelegate(asyncProgressUpdated), + new ObservedProgression.ReportDelegate(asyncEnded) ) ); } @@ -60,7 +55,8 @@ namespace Nuclex.Support.Tracking { this.childs.Add( new ObservedProgression( progression, - this.asyncProgressUpdatedDelegate, this.asyncEndedDelegate + new ObservedProgression.ReportDelegate(asyncProgressUpdated), + new ObservedProgression.ReportDelegate(asyncEnded) ) ); @@ -160,12 +156,6 @@ namespace Nuclex.Support.Tracking { /// Summed weight of all progression in the set private float totalWeight; - /// Delegate for the asyncProgressUpdated() method - private ObservedProgression.ReportDelegate asyncProgressUpdatedDelegate; - /// Delegate for the asyncEnded() method - private ObservedProgression.ReportDelegate asyncEndedDelegate; - - } } // namespace Nuclex.Support.Tracking