Skip to content

Commit 332baf1

Browse files
stephentoubjkotas
authored andcommitted
Replace a few new string(char, 1) with char.ToString(char) (dotnet/coreclr#21406)
Slightly cleaner, slightly faster. Commit migrated from dotnet/coreclr@d1433bc
1 parent e7ea2cb commit 332baf1

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ public unsafe virtual int IndexOf(string source, char value, int startIndex, int
977977
if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal && options != CompareOptions.OrdinalIgnoreCase))
978978
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
979979

980-
return IndexOf(source, new string(value, 1), startIndex, count, options, null);
980+
return IndexOf(source, char.ToString(value), startIndex, count, options, null);
981981
}
982982

983983
public unsafe virtual int IndexOf(string source, string value, int startIndex, int count, CompareOptions options)
@@ -1268,7 +1268,7 @@ public virtual int LastIndexOf(string source, char value, int startIndex, int co
12681268
}
12691269

12701270
if (GlobalizationMode.Invariant)
1271-
return InvariantLastIndexOf(source, new string(value, 1), startIndex, count, (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
1271+
return InvariantLastIndexOf(source, char.ToString(value), startIndex, count, (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
12721272

12731273
return LastIndexOfCore(source, value.ToString(), startIndex, count, options);
12741274
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,7 @@ internal void GetNFIValues(NumberFormatInfo nfi)
23592359
nfi.nativeDigits = new string[10];
23602360
for (int i = 0; i < nfi.nativeDigits.Length; i++)
23612361
{
2362-
nfi.nativeDigits[i] = new string(digits[i], 1);
2362+
nfi.nativeDigits[i] = char.ToString(digits[i]);
23632363
}
23642364

23652365
nfi.digitSubstitution = GetDigitSubstitution(_sRealName);

src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ internal static string[] GetAllDateTimes(DateTime dateTime, char format, DateTim
13711371
case 'O':
13721372
case 's':
13731373
case 'u':
1374-
results = new string[] { Format(dateTime, new string(format, 1), dtfi) };
1374+
results = new string[] { Format(dateTime, char.ToString(format), dtfi) };
13751375
break;
13761376
default:
13771377
throw new FormatException(SR.Format_InvalidString);

0 commit comments

Comments
 (0)