Skip to content

Commit 9be281b

Browse files
authored
Use Dictionary with StringComparer to avoid string allocations in System.Data.Common (#120603)
1 parent 26b8e5d commit 9be281b

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/libraries/System.Data.Common/src/System/Data/Common/AdapterUtil.Common.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,14 @@ internal static DataRow[] SelectAdapterRows(DataTable dataTable, bool sorted)
779779
// { "a", "A", "a1" } -> { "a", "A2", "a1" }
780780
internal static void BuildSchemaTableInfoTableNames(string[] columnNameArray)
781781
{
782-
Dictionary<string, int> hash = new Dictionary<string, int>(columnNameArray.Length);
782+
Dictionary<string, int> hash = new Dictionary<string, int>(columnNameArray.Length, StringComparer.InvariantCultureIgnoreCase);
783783

784784
int startIndex = columnNameArray.Length; // lowest non-unique index
785785
for (int i = columnNameArray.Length - 1; 0 <= i; --i)
786786
{
787787
string columnName = columnNameArray[i];
788788
if ((null != columnName) && (0 < columnName.Length))
789789
{
790-
columnName = columnName.ToLowerInvariant();
791790
int index;
792791
if (hash.TryGetValue(columnName, out index))
793792
{
@@ -813,7 +812,6 @@ internal static void BuildSchemaTableInfoTableNames(string[] columnNameArray)
813812
}
814813
else
815814
{
816-
columnName = columnName.ToLowerInvariant();
817815
if (i != hash[columnName])
818816
{
819817
GenerateUniqueName(hash, ref columnNameArray[i], i, 1);
@@ -827,8 +825,7 @@ private static int GenerateUniqueName(Dictionary<string, int> hash, ref string c
827825
for (; ; ++uniqueIndex)
828826
{
829827
string uniqueName = columnName + uniqueIndex.ToString(CultureInfo.InvariantCulture);
830-
string lowerName = uniqueName.ToLowerInvariant();
831-
if (hash.TryAdd(lowerName, index))
828+
if (hash.TryAdd(uniqueName, index))
832829
{
833830
columnName = uniqueName;
834831
break;

0 commit comments

Comments
 (0)