summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorstephentoub <stoub@microsoft.com>2015-11-13 08:59:12 -0500
committerstephentoub <stoub@microsoft.com>2015-11-13 10:25:30 -0500
commitb5920928d8824aba40a6a848729979d5b26028f4 (patch)
tree56ee225fc9f7e59f090d5d4bba243029788483e0 /src
parent09917c891af09a41dd9e2159d1c0095881e1a43f (diff)
downloadcoreclr-b5920928d8824aba40a6a848729979d5b26028f4.tar.gz
coreclr-b5920928d8824aba40a6a848729979d5b26028f4.tar.bz2
coreclr-b5920928d8824aba40a6a848729979d5b26028f4.zip
Pass target string lengths to ICU on Unix
Our current ICU shims for StartsWith, EndsWith, IndexOf, and LastIndexOf take the length of the source string but not the length of the target string. This forces ICU to compute the length of the string by searching for a null terminator. We can save those costs and be more accurate around nulls in the target string by passing the known length in.
Diffstat (limited to 'src')
-rw-r--r--src/corefx/System.Globalization.Native/collation.cpp16
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs8
-rw-r--r--src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs8
3 files changed, 16 insertions, 16 deletions
diff --git a/src/corefx/System.Globalization.Native/collation.cpp b/src/corefx/System.Globalization.Native/collation.cpp
index ca82a1bca6..024e0e9456 100644
--- a/src/corefx/System.Globalization.Native/collation.cpp
+++ b/src/corefx/System.Globalization.Native/collation.cpp
@@ -72,7 +72,7 @@ Function:
IndexOf
*/
extern "C" int32_t
-IndexOf(const char* lpLocaleName, const UChar* lpTarget, const UChar* lpSource, int32_t cwSourceLength, int32_t options)
+IndexOf(const char* lpLocaleName, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options)
{
static_assert(USEARCH_DONE == -1, "managed side requires -1 for not found");
@@ -82,7 +82,7 @@ IndexOf(const char* lpLocaleName, const UChar* lpTarget, const UChar* lpSource,
if (U_SUCCESS(err))
{
- UStringSearch* pSearch = usearch_openFromCollator(lpTarget, -1, lpSource, cwSourceLength, pColl, nullptr, &err);
+ UStringSearch* pSearch = usearch_openFromCollator(lpTarget, cwTargetLength, lpSource, cwSourceLength, pColl, nullptr, &err);
if (U_SUCCESS(err))
{
@@ -101,7 +101,7 @@ Function:
LastIndexOf
*/
extern "C" int32_t LastIndexOf(
- const char* lpLocaleName, const UChar* lpTarget, const UChar* lpSource, int32_t cwSourceLength, int32_t options)
+ const char* lpLocaleName, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options)
{
static_assert(USEARCH_DONE == -1, "managed side requires -1 for not found");
@@ -111,7 +111,7 @@ extern "C" int32_t LastIndexOf(
if (U_SUCCESS(err))
{
- UStringSearch* pSearch = usearch_openFromCollator(lpTarget, -1, lpSource, cwSourceLength, pColl, nullptr, &err);
+ UStringSearch* pSearch = usearch_openFromCollator(lpTarget, cwTargetLength, lpSource, cwSourceLength, pColl, nullptr, &err);
if (U_SUCCESS(err))
{
@@ -202,7 +202,7 @@ IndexOfOrdinalIgnoreCase(
Return value is a "Win32 BOOL" (1 = true, 0 = false)
*/
extern "C" int32_t StartsWith(
- const char* lpLocaleName, const UChar* lpTarget, const UChar* lpSource, int32_t cwSourceLength, int32_t options)
+ const char* lpLocaleName, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options)
{
int32_t result = FALSE;
UErrorCode err = U_ZERO_ERROR;
@@ -210,7 +210,7 @@ extern "C" int32_t StartsWith(
if (U_SUCCESS(err))
{
- UStringSearch* pSearch = usearch_openFromCollator(lpTarget, -1, lpSource, cwSourceLength, pColl, nullptr, &err);
+ UStringSearch* pSearch = usearch_openFromCollator(lpTarget, cwTargetLength, lpSource, cwSourceLength, pColl, nullptr, &err);
int32_t idx = USEARCH_DONE;
if (U_SUCCESS(err))
@@ -264,7 +264,7 @@ extern "C" int32_t StartsWith(
Return value is a "Win32 BOOL" (1 = true, 0 = false)
*/
extern "C" int32_t EndsWith(
- const char* lpLocaleName, const UChar* lpTarget, const UChar* lpSource, int32_t cwSourceLength, int32_t options)
+ const char* lpLocaleName, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options)
{
int32_t result = FALSE;
UErrorCode err = U_ZERO_ERROR;
@@ -272,7 +272,7 @@ extern "C" int32_t EndsWith(
if (U_SUCCESS(err))
{
- UStringSearch* pSearch = usearch_openFromCollator(lpTarget, -1, lpSource, cwSourceLength, pColl, nullptr, &err);
+ UStringSearch* pSearch = usearch_openFromCollator(lpTarget, cwTargetLength, lpSource, cwSourceLength, pColl, nullptr, &err);
int32_t idx = USEARCH_DONE;
if (U_SUCCESS(err))
diff --git a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
index c236c03cfa..5b2f03e57c 100644
--- a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
+++ b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
@@ -13,21 +13,21 @@ internal static partial class Interop
internal unsafe static extern int CompareString(byte[] localeName, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options);
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode)]
- internal unsafe static extern int IndexOf(byte[] localeName, string target, char* pSource, int cwSourceLength, CompareOptions options);
+ internal unsafe static extern int IndexOf(byte[] localeName, string target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options);
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode)]
- internal unsafe static extern int LastIndexOf(byte[] localeName, string target, char* pSource, int cwSourceLength, CompareOptions options);
+ internal unsafe static extern int LastIndexOf(byte[] localeName, string target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options);
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode)]
internal unsafe static extern int IndexOfOrdinalIgnoreCase(string target, int cwTargetLength, char* pSource, int cwSourceLength, bool findLast);
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
- internal unsafe static extern bool StartsWith(byte[] localeName, string target, string source, int cwSourceLength, CompareOptions options);
+ internal unsafe static extern bool StartsWith(byte[] localeName, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
- internal unsafe static extern bool EndsWith(byte[] localeName, string target, string source, int cwSourceLength, CompareOptions options);
+ internal unsafe static extern bool EndsWith(byte[] localeName, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode)]
internal unsafe static extern int GetSortKey(byte[] localeName, string str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options);
diff --git a/src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs b/src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs
index 9a2a35c04a..d65ac8b4e8 100644
--- a/src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs
+++ b/src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs
@@ -160,7 +160,7 @@ namespace System.Globalization
fixed (char* pSource = source)
{
- int index = Interop.GlobalizationInterop.IndexOf(m_sortNameAsUtf8, target, pSource + startIndex, count, options);
+ int index = Interop.GlobalizationInterop.IndexOf(m_sortNameAsUtf8, target, target.Length, pSource + startIndex, count, options);
return index != -1 ? index + startIndex : -1;
}
@@ -188,7 +188,7 @@ namespace System.Globalization
fixed (char* pSource = source)
{
- int lastIndex = Interop.GlobalizationInterop.LastIndexOf(m_sortNameAsUtf8, target, pSource + (startIndex - count + 1), count, options);
+ int lastIndex = Interop.GlobalizationInterop.LastIndexOf(m_sortNameAsUtf8, target, target.Length, pSource + (startIndex - count + 1), count, options);
return lastIndex != -1 ? lastIndex + leftStartIndex : -1;
}
@@ -200,7 +200,7 @@ namespace System.Globalization
Contract.Assert(!string.IsNullOrEmpty(prefix));
Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
- return Interop.GlobalizationInterop.StartsWith(m_sortNameAsUtf8, prefix, source, source.Length, options);
+ return Interop.GlobalizationInterop.StartsWith(m_sortNameAsUtf8, prefix, prefix.Length, source, source.Length, options);
}
private bool EndsWith(string source, string suffix, CompareOptions options)
@@ -209,7 +209,7 @@ namespace System.Globalization
Contract.Assert(!string.IsNullOrEmpty(suffix));
Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
- return Interop.GlobalizationInterop.EndsWith(m_sortNameAsUtf8, suffix, source, source.Length, options);
+ return Interop.GlobalizationInterop.EndsWith(m_sortNameAsUtf8, suffix, suffix.Length, source, source.Length, options);
}
// -----------------------------