Skip to content

Commit 9c8e754

Browse files
committed
avoid some allocations when opening a connection
fixes #3363
1 parent 6d2473d commit 9c8e754

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ internal static Version GetAssemblyVersion()
764764

765765
internal static bool IsAzureSynapseOnDemandEndpoint(string dataSource)
766766
{
767-
return IsEndpoint(dataSource, ONDEMAND_PREFIX)
767+
return IsEndpoint(dataSource, s_azureSqlServerOnDemandEndpoints)
768768
|| dataSource.Contains(AZURE_SYNAPSE)
769769
|| dataSource.Contains(FABRIC_DATAWAREHOUSE)
770770
|| dataSource.Contains(PBI_DATAWAREHOUSE)
@@ -777,14 +777,20 @@ internal static bool IsAzureSynapseOnDemandEndpoint(string dataSource)
777777
AZURE_SQL_USGOV,
778778
AZURE_SQL_CHINA,
779779
AZURE_SQL_FABRIC };
780+
781+
internal static readonly string[] s_azureSqlServerOnDemandEndpoints = { ONDEMAND_PREFIX + AZURE_SQL,
782+
ONDEMAND_PREFIX + AZURE_SQL_GERMANY,
783+
ONDEMAND_PREFIX + AZURE_SQL_USGOV,
784+
ONDEMAND_PREFIX + AZURE_SQL_CHINA,
785+
ONDEMAND_PREFIX + AZURE_SQL_FABRIC };
780786

781787
internal static bool IsAzureSqlServerEndpoint(string dataSource)
782788
{
783-
return IsEndpoint(dataSource, null);
789+
return IsEndpoint(dataSource, s_azureSqlServerEndpoints);
784790
}
785791

786792
// This method assumes dataSource parameter is in TCP connection string format.
787-
private static bool IsEndpoint(string dataSource, string prefix)
793+
private static bool IsEndpoint(string dataSource, string[] endpoints)
788794
{
789795
int length = dataSource.Length;
790796
// remove server port
@@ -805,8 +811,6 @@ private static bool IsEndpoint(string dataSource, string prefix)
805811
foundIndex = -1;
806812
}
807813

808-
809-
810814
if (foundIndex > 0)
811815
{
812816
length = foundIndex;
@@ -819,9 +823,9 @@ private static bool IsEndpoint(string dataSource, string prefix)
819823
}
820824

821825
// check if servername ends with any endpoints
822-
for (int index = 0; index < s_azureSqlServerEndpoints.Length; index++)
826+
for (int index = 0; index < endpoints.Length; index++)
823827
{
824-
string endpoint = string.IsNullOrEmpty(prefix) ? s_azureSqlServerEndpoints[index] : prefix + s_azureSqlServerEndpoints[index];
828+
string endpoint = endpoints[index];
825829
if (length > endpoint.Length)
826830
{
827831
if (string.Compare(dataSource, length - endpoint.Length, endpoint, 0, endpoint.Length, StringComparison.OrdinalIgnoreCase) == 0)

0 commit comments

Comments
 (0)