THRIFT-4879 general performance improvements for netstd library
Client: netstd
Patch: Jens Geyer
This closes #1808
diff --git a/lib/netstd/Thrift/Collections/THashSet.cs b/lib/netstd/Thrift/Collections/THashSet.cs
index 011f0a0..ffab577 100644
--- a/lib/netstd/Thrift/Collections/THashSet.cs
+++ b/lib/netstd/Thrift/Collections/THashSet.cs
@@ -23,45 +23,56 @@
// ReSharper disable once InconsistentNaming
public class THashSet<T> : ICollection<T>
{
- private readonly HashSet<T> _set = new HashSet<T>();
+ private readonly HashSet<T> Items;
- public int Count => _set.Count;
+ public THashSet()
+ {
+ Items = new HashSet<T>();
+ }
+
+ public THashSet(int capacity)
+ {
+ // TODO: uncomment capacity when NET Standard also implements it
+ Items = new HashSet<T>(/*capacity*/);
+ }
+
+ public int Count => Items.Count;
public bool IsReadOnly => false;
public void Add(T item)
{
- _set.Add(item);
+ Items.Add(item);
}
public void Clear()
{
- _set.Clear();
+ Items.Clear();
}
public bool Contains(T item)
{
- return _set.Contains(item);
+ return Items.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
- _set.CopyTo(array, arrayIndex);
+ Items.CopyTo(array, arrayIndex);
}
public IEnumerator GetEnumerator()
{
- return _set.GetEnumerator();
+ return Items.GetEnumerator();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
- return ((IEnumerable<T>) _set).GetEnumerator();
+ return ((IEnumerable<T>) Items).GetEnumerator();
}
public bool Remove(T item)
{
- return _set.Remove(item);
+ return Items.Remove(item);
}
}
-}
\ No newline at end of file
+}