From 984bc776edf7b2dcabc6ffaf1b157fb2afc9f57a Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Thu, 8 Dec 2016 16:28:08 -0800 Subject: [PATCH] Remove private TimeZoneInfoComparer (dotnet/coreclr#8512) Use Comparison instead of IComparer to sort the list of TimeZoneInfos, which moves the comparison code to the sole place where it is used, and now that Array.Sort is implemented in terms of Comparison instead of IComparer, avoids some unnecessary intermediate allocations. Commit migrated from https://github.com/dotnet/coreclr/commit/3ff4bd7b39629f6e681d7211dade57369ea586b3 --- src/coreclr/src/mscorlib/src/System/TimeZoneInfo.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/coreclr/src/mscorlib/src/System/TimeZoneInfo.cs b/src/coreclr/src/mscorlib/src/System/TimeZoneInfo.cs index d8662d4..c1e9ba3 100644 --- a/src/coreclr/src/mscorlib/src/System/TimeZoneInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/TimeZoneInfo.cs @@ -1006,7 +1006,12 @@ namespace System { } // sort and copy the TimeZoneInfo's into a ReadOnlyCollection for the user - list.Sort(new TimeZoneInfoComparer()); + list.Sort((x, y) => + { + // sort by BaseUtcOffset first and by DisplayName second - this is similar to the Windows Date/Time control panel + int comparison = x.BaseUtcOffset.CompareTo(y.BaseUtcOffset); + return comparison == 0 ? string.CompareOrdinal(x.DisplayName, y.DisplayName) : comparison; + }); cachedData.m_readOnlySystemTimeZones = new ReadOnlyCollection(list); } @@ -5686,14 +5691,6 @@ namespace System { } } - private class TimeZoneInfoComparer : System.Collections.Generic.IComparer { - int System.Collections.Generic.IComparer.Compare(TimeZoneInfo x, TimeZoneInfo y) { - // sort by BaseUtcOffset first and by DisplayName second - this is similar to the Windows Date/Time control panel - int comparison = x.BaseUtcOffset.CompareTo(y.BaseUtcOffset); - return comparison == 0 ? String.Compare(x.DisplayName, y.DisplayName, StringComparison.Ordinal) : comparison; - } - } - #if PLATFORM_UNIX private struct TZifType { -- 2.7.4