Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormzhaolz <mzhaod@gmail.com>2016-09-30 01:34:28 +0300
committerStephen Toub <stoub@microsoft.com>2016-09-30 01:34:28 +0300
commitbef119221d98912cda3076ca67a96f0a8177c97d (patch)
tree4d1e70cbc4ef3e85f3752a8edb2ab9abfe8d2366 /src
parent3d4e97e0c9d375041f29e498727e8476d8f6cf0b (diff)
Reduce rotations done in Sorted Set's IntersectWithEnumerable. (#12164)
* Fixes issue #6414 with the fix described in the issue, reducing the rotations done in SortedSet's IntersectWithEnumerable. * Avoiding duplication b/w SortedSet and TreeSubSet's IntersectWithEnumerable. * Modifying TreeSubSet to override SortedSet.IntersectWithEnumerable only in debug mode.
Diffstat (limited to 'src')
-rw-r--r--src/System.Collections/src/System/Collections/Generic/SortedSet.cs27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/System.Collections/src/System/Collections/Generic/SortedSet.cs b/src/System.Collections/src/System/Collections/Generic/SortedSet.cs
index df67684635..04ceafa45a 100644
--- a/src/System.Collections/src/System/Collections/Generic/SortedSet.cs
+++ b/src/System.Collections/src/System/Collections/Generic/SortedSet.cs
@@ -1344,11 +1344,14 @@ namespace System.Collections.Generic
if (Contains(item))
{
toSave.Add(item);
- Remove(item);
}
}
- Clear();
- AddAllElements(toSave);
+
+ if (toSave.Count < Count)
+ {
+ Clear();
+ AddAllElements(toSave);
+ }
}
/// <summary>
@@ -2196,23 +2199,13 @@ namespace System.Collections.Generic
return ret;
}
+#if DEBUG
internal override void IntersectWithEnumerable(IEnumerable<T> other)
{
- List<T> toSave = new List<T>(this.Count);
- foreach (T item in other)
- {
- if (Contains(item))
- {
- toSave.Add(item);
- Remove(item);
- }
- }
- Clear();
- AddAllElements(toSave);
-#if DEBUG
- Debug.Assert(this.versionUpToDate() && _root == _underlying.FindRange(_min, _max));
-#endif
+ base.IntersectWithEnumerable(other);
+ Debug.Assert(versionUpToDate() && _root == _underlying.FindRange(_min, _max));
}
+#endif
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{