diff options
author | Adam Sitnik <adam.sitnik@microsoft.com> | 2019-06-15 06:48:50 +0000 |
---|---|---|
committer | Adam Sitnik <adam.sitnik@microsoft.com> | 2019-06-15 06:48:50 +0000 |
commit | 94ddbf6ecf0363c1b0dd2de2936a4fa1caec6f7d (patch) | |
tree | b349ba2ce9382def47aeeedc5e5afae68b395c98 /src/System.Private.CoreLib | |
parent | f395bed0a5a4e44be9f8e0d421e93a1188e305e8 (diff) | |
download | coreclr-94ddbf6ecf0363c1b0dd2de2936a4fa1caec6f7d.tar.gz coreclr-94ddbf6ecf0363c1b0dd2de2936a4fa1caec6f7d.tar.bz2 coreclr-94ddbf6ecf0363c1b0dd2de2936a4fa1caec6f7d.zip |
simplify the code
Diffstat (limited to 'src/System.Private.CoreLib')
-rw-r--r-- | src/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs | 2 | ||||
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs | 34 |
2 files changed, 7 insertions, 29 deletions
diff --git a/src/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs b/src/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs index c9ca63254d..300756faf7 100644 --- a/src/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs +++ b/src/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs @@ -12,7 +12,7 @@ internal static partial class Interop internal static partial class Globalization { [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortHandle")] - internal static extern unsafe ResultCode GetSortHandle(byte[] localeName, out IntPtr sortHandle); + internal static extern unsafe ResultCode GetSortHandle(string localeName, out IntPtr sortHandle); [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CloseSortHandle")] internal static extern unsafe void CloseSortHandle(IntPtr handle); diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs index d605985c65..c61526d11e 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs @@ -936,7 +936,12 @@ namespace System.Globalization { if (!s_sortNameToSortHandleCache.TryGetValue(sortName, out IntPtr result)) { - result = GetSortHandle(sortName); + var resultCode = Interop.Globalization.GetSortHandle(sortName, out result); + + if (resultCode == Interop.Globalization.ResultCode.OutOfMemory) + throw new OutOfMemoryException(); + else if (resultCode != Interop.Globalization.ResultCode.Success) + throw new ExternalException(SR.Arg_ExternalException); try { @@ -953,33 +958,6 @@ namespace System.Globalization return result; } } - - private static IntPtr GetSortHandle(string sortName) - { - switch(Interop.Globalization.GetSortHandle(GetNullTerminatedUtf8String(sortName), out IntPtr sortHandle)) - { - case Interop.Globalization.ResultCode.Success: - return sortHandle; - case Interop.Globalization.ResultCode.OutOfMemory: - throw new OutOfMemoryException(); - default: - throw new ExternalException(SR.Arg_ExternalException); - } - } - - private static byte[] GetNullTerminatedUtf8String(string s) - { - int byteLen = System.Text.Encoding.UTF8.GetByteCount(s); - - // Allocate an extra byte (which defaults to 0) as the null terminator. - byte[] buffer = new byte[byteLen + 1]; - - int bytesWritten = System.Text.Encoding.UTF8.GetBytes(s, 0, s.Length, buffer, 0); - - Debug.Assert(bytesWritten == byteLen); - - return buffer; - } } // See https://github.com/dotnet/coreclr/blob/master/src/utilcode/util_nodependencies.cpp#L970 |