Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e5ff280

Browse files
authored
Replace custom AnsiToLower with more efficient ToLowerAsciiInvariant (#21121)
Avoids all of the StringBuilder-related costs.
1 parent cc5df16 commit e5ff280

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

src/System.Private.CoreLib/shared/System/Globalization/CultureData.cs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,35 +2407,8 @@ internal void GetNFIValues(NumberFormatInfo nfi)
24072407

24082408
// Helper
24092409
// This is ONLY used for caching names and shouldn't be used for anything else
2410-
internal static string AnsiToLower(string testString)
2411-
{
2412-
int index = 0;
2413-
2414-
while (index<testString.Length && (testString[index]<'A' || testString[index]>'Z' ))
2415-
{
2416-
index++;
2417-
}
2418-
if (index >= testString.Length)
2419-
{
2420-
return testString; // we didn't really change the string
2421-
}
2422-
2423-
StringBuilder sb = new StringBuilder(testString.Length);
2424-
for (int i=0; i<index; i++)
2425-
{
2426-
sb.Append(testString[i]);
2427-
}
2428-
2429-
sb.Append((char) (testString[index] -'A' + 'a'));
2430-
2431-
for (int ich = index+1; ich < testString.Length; ich++)
2432-
{
2433-
char ch = testString[ich];
2434-
sb.Append(ch <= 'Z' && ch >= 'A' ? (char)(ch - 'A' + 'a') : ch);
2435-
}
2436-
2437-
return (sb.ToString());
2438-
}
2410+
internal static string AnsiToLower(string testString) =>
2411+
TextInfo.ToLowerAsciiInvariant(testString);
24392412

24402413
/// <remarks>
24412414
/// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation

src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ private unsafe string ChangeCaseCommon<TConversion>(string source) where TConver
451451
}
452452
}
453453

454-
private static unsafe string ToLowerAsciiInvariant(string s)
454+
internal static unsafe string ToLowerAsciiInvariant(string s)
455455
{
456456
if (s.Length == 0)
457457
{

0 commit comments

Comments
 (0)