diff options
author | Jb Evain <jbevain@gmail.com> | 2008-04-22 22:05:45 +0400 |
---|---|---|
committer | Jb Evain <jbevain@gmail.com> | 2008-04-22 22:05:45 +0400 |
commit | 658785d265216eab0f27052ba0a887d50e0bce97 (patch) | |
tree | 5e08209e5d92a6535df78d1c7ecbec3937f1871c /mcs/class/System.Core/System.Linq/Enumerable.cs | |
parent | 635f13774a46d4261d59ba14960ae79ec3dd6e0e (diff) |
2008-04-22 Jb Evain <jbevain@novell.com>
* Enumerable.cs (ToReadOnlyCollection): optimization, use
a generic singleton for empty read only collections.
svn path=/trunk/mcs/; revision=101474
Diffstat (limited to 'mcs/class/System.Core/System.Linq/Enumerable.cs')
-rw-r--r-- | mcs/class/System.Core/System.Linq/Enumerable.cs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/mcs/class/System.Core/System.Linq/Enumerable.cs b/mcs/class/System.Core/System.Linq/Enumerable.cs index 6c602fe14ef..9d55a55ff3d 100644 --- a/mcs/class/System.Core/System.Linq/Enumerable.cs +++ b/mcs/class/System.Core/System.Linq/Enumerable.cs @@ -2283,7 +2283,7 @@ namespace System.Linq if (comparer == null) comparer = EqualityComparer<TKey>.Default; - + var dict = new Dictionary<TKey, TSource> (comparer); foreach (var e in source) dict.Add (keySelector (e), e); @@ -2455,10 +2455,14 @@ namespace System.Linq #endregion + class ReadOnlyCollectionOf<T> { + public static readonly ReadOnlyCollection<T> Empty = new ReadOnlyCollection<T> (new T [0]); + } + internal static ReadOnlyCollection<TSource> ToReadOnlyCollection<TSource> (this IEnumerable<TSource> source) { if (source == null) - return new ReadOnlyCollection<TSource> (new TSource [0]); // could we singlotenize that? + return ReadOnlyCollectionOf<TSource>.Empty; var ro = source as ReadOnlyCollection<TSource>; if (ro != null) |