An easy fix for dotnet/coreclr#6760 (dotnet/coreclr#6770)
authorViacheslav Nikolaev <v.nikolaev@samsung.com>
Thu, 18 Aug 2016 12:12:09 +0000 (15:12 +0300)
committerJan Kotas <jkotas@microsoft.com>
Thu, 18 Aug 2016 12:12:09 +0000 (05:12 -0700)
As mentioned in dotnet/coreclr#6760 we can postpone the calculation of the NeedsTurkishCasing property.

Conflicts:
src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs

Commit migrated from https://github.com/dotnet/coreclr/commit/c6888eac104adf444ad4db63aedd5cee98ac088f

src/coreclr/src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs

index 4681170..03a28b3 100644 (file)
@@ -10,7 +10,13 @@ namespace System.Globalization
 {
     public partial class TextInfo
     {
-        private bool m_needsTurkishCasing;
+        enum TurkishCasing
+        {
+            NotInitialized,
+            NotNeeded,
+            Needed
+        }
+        private TurkishCasing m_needsTurkishCasing;
 
         //////////////////////////////////////////////////////////////////////////
         ////
@@ -29,7 +35,7 @@ namespace System.Globalization
 
         private void FinishInitialization(string textInfoName)
         {
-            m_needsTurkishCasing = NeedsTurkishCasing(textInfoName);
+            m_needsTurkishCasing = TurkishCasing.NotInitialized;
         }
 
         [SecuritySafeCritical]
@@ -107,13 +113,20 @@ namespace System.Globalization
             {
                 Interop.GlobalizationInterop.ChangeCaseInvariant(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
             }
-            else if (m_needsTurkishCasing)
-            {
-                Interop.GlobalizationInterop.ChangeCaseTurkish(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
-            }
             else
             {
-                Interop.GlobalizationInterop.ChangeCase(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
+                if (m_needsTurkishCasing == TurkishCasing.NotInitialized)
+                {
+                    m_needsTurkishCasing = NeedsTurkishCasing(m_textInfoName) ? TurkishCasing.Needed : TurkishCasing.NotNeeded;
+                }
+                if ( m_needsTurkishCasing == TurkishCasing.Needed)
+                {
+                    Interop.GlobalizationInterop.ChangeCaseTurkish(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
+                }
+                else
+                {
+                    Interop.GlobalizationInterop.ChangeCase(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
+                }
             }
         }