Commit 89781fef authored by Nick Craver's avatar Nick Craver

Cleanup: ProfileStorage

parent 7384ec02
...@@ -24,11 +24,11 @@ public struct ProfiledCommandEnumerable : IEnumerable<IProfiledCommand> ...@@ -24,11 +24,11 @@ public struct ProfiledCommandEnumerable : IEnumerable<IProfiledCommand>
/// </summary> /// </summary>
public struct Enumerator : IEnumerator<IProfiledCommand> public struct Enumerator : IEnumerator<IProfiledCommand>
{ {
ProfileStorage Head; private ProfileStorage Head;
ProfileStorage CurrentBacker; private ProfileStorage CurrentBacker;
bool IsEmpty => Head == null; private bool IsEmpty => Head == null;
bool IsUnstartedOrFinished => CurrentBacker == null; private bool IsUnstartedOrFinished => CurrentBacker == null;
internal Enumerator(ProfileStorage head) internal Enumerator(ProfileStorage head)
{ {
...@@ -81,7 +81,7 @@ public void Dispose() ...@@ -81,7 +81,7 @@ public void Dispose()
} }
} }
ProfileStorage Head; private readonly ProfileStorage Head;
internal ProfiledCommandEnumerable(ProfileStorage head) internal ProfiledCommandEnumerable(ProfileStorage head)
{ {
...@@ -94,20 +94,11 @@ internal ProfiledCommandEnumerable(ProfileStorage head) ...@@ -94,20 +94,11 @@ internal ProfiledCommandEnumerable(ProfileStorage head)
/// ///
/// `foreach` will automatically use this method. /// `foreach` will automatically use this method.
/// </summary> /// </summary>
public Enumerator GetEnumerator() public Enumerator GetEnumerator() => new Enumerator(Head);
{
return new Enumerator(Head);
}
IEnumerator<IProfiledCommand> IEnumerable<IProfiledCommand>.GetEnumerator() IEnumerator<IProfiledCommand> IEnumerable<IProfiledCommand>.GetEnumerator() => GetEnumerator();
{
return GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
{
return GetEnumerator();
}
} }
/// <summary> /// <summary>
...@@ -116,7 +107,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() ...@@ -116,7 +107,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
/// ///
/// Performs better than ConcurrentBag, which is important since profiling code shouldn't impact timings. /// Performs better than ConcurrentBag, which is important since profiling code shouldn't impact timings.
/// </summary> /// </summary>
sealed class ConcurrentProfileStorageCollection internal sealed class ConcurrentProfileStorageCollection
{ {
// internal for test purposes // internal for test purposes
internal static int AllocationCount = 0; internal static int AllocationCount = 0;
...@@ -124,10 +115,10 @@ sealed class ConcurrentProfileStorageCollection ...@@ -124,10 +115,10 @@ sealed class ConcurrentProfileStorageCollection
// It is, by definition, impossible for an element to be in 2 intrusive collections // It is, by definition, impossible for an element to be in 2 intrusive collections
// and we force Enumeration to release any reference to the collection object // and we force Enumeration to release any reference to the collection object
// so we can **always** pool these. // so we can **always** pool these.
const int PoolSize = 64; private const int PoolSize = 64;
static ConcurrentProfileStorageCollection[] Pool = new ConcurrentProfileStorageCollection[PoolSize]; private static readonly ConcurrentProfileStorageCollection[] Pool = new ConcurrentProfileStorageCollection[PoolSize];
volatile ProfileStorage Head; private volatile ProfileStorage Head;
private ConcurrentProfileStorageCollection() { } private ConcurrentProfileStorageCollection() { }
...@@ -154,9 +145,10 @@ internal static int CountInPool() ...@@ -154,9 +145,10 @@ internal static int CountInPool()
/// ///
/// The element can only be a member of *one* bag. /// The element can only be a member of *one* bag.
/// </summary> /// </summary>
/// <param name="command">The command to add.</param>
public void Add(ProfileStorage command) public void Add(ProfileStorage command)
{ {
do while (true)
{ {
var cur = Head; var cur = Head;
command.NextElement = cur; command.NextElement = cur;
...@@ -167,7 +159,7 @@ public void Add(ProfileStorage command) ...@@ -167,7 +159,7 @@ public void Add(ProfileStorage command)
#pragma warning restore 420 #pragma warning restore 420
if (object.ReferenceEquals(got, cur)) break; if (object.ReferenceEquals(got, cur)) break;
} while (true); }
} }
/// <summary> /// <summary>
...@@ -219,9 +211,7 @@ public static ConcurrentProfileStorageCollection GetOrCreate() ...@@ -219,9 +211,7 @@ public static ConcurrentProfileStorageCollection GetOrCreate()
} }
Interlocked.Increment(ref AllocationCount); Interlocked.Increment(ref AllocationCount);
found = new ConcurrentProfileStorageCollection(); return new ConcurrentProfileStorageCollection();
return found;
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment