Lucene.Net.Core.Util.ArrayUtil.GetNaturalComparer(): Optimized by resolving generic closing type only 1 time.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/8fabf085 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/8fabf085 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/8fabf085 Branch: refs/heads/api-work Commit: 8fabf0855da17e23690413dee1652174e4cea507 Parents: 51f56d5 Author: Shad Storhaug <[email protected]> Authored: Fri Mar 17 17:07:47 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Fri Mar 17 17:07:47 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Util/ArrayUtil.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8fabf085/src/Lucene.Net.Core/Util/ArrayUtil.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/ArrayUtil.cs b/src/Lucene.Net.Core/Util/ArrayUtil.cs index d50954a..f44a6d7 100644 --- a/src/Lucene.Net.Core/Util/ArrayUtil.cs +++ b/src/Lucene.Net.Core/Util/ArrayUtil.cs @@ -825,9 +825,11 @@ namespace Lucene.Net.Util public static IComparer<T> GetNaturalComparer<T>() //where T : IComparable<T> // LUCENENET specific: removing constraint because in .NET, it is not needed { + Type genericClosingType = typeof(T); + // LUCENENET specific - we need to ensure that strings are compared // in a culture-insenitive manner. - if (typeof(T).Equals(typeof(string))) + if (genericClosingType.Equals(typeof(string))) { return (IComparer<T>)StringComparer.Ordinal; } @@ -835,7 +837,7 @@ namespace Lucene.Net.Util // implements IComparable<T>, otherwise use Comparer<T>.Default. // This allows the comparison to be customized, but it is not mandatory // to implement IComparable<T>. - else if (typeof(IComparable<T>).GetTypeInfo().IsAssignableFrom(typeof(T))) + else if (typeof(IComparable<T>).GetTypeInfo().IsAssignableFrom(genericClosingType)) { return new NaturalComparer<T>(); }
