Skip to content

Commit 0be2756

Browse files
authored
Reduce AOT binary size (#3091)
* Removed reference to DataContractJsonSerializer. Enable partial trimming of System.Diagnostics and one Hashtable * Adjusted deserialization after benchmarking * Removed unused usings
1 parent e25c24a commit 0be2756

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Collections;
76
using System.Collections.Generic;
87
using System.Diagnostics;
98
using System.Globalization;
@@ -396,12 +395,12 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
396395
if (_networkLibrary != null)
397396
{ // MDAC 83525
398397
string networkLibrary = _networkLibrary.Trim().ToLower(CultureInfo.InvariantCulture);
399-
Hashtable netlib = NetlibMapping();
398+
Dictionary<string, string> netlib = NetlibMapping();
400399
if (!netlib.ContainsKey(networkLibrary))
401400
{
402401
throw ADP.InvalidConnectionOptionValue(KEY.Network_Library);
403402
}
404-
_networkLibrary = (string)netlib[networkLibrary];
403+
_networkLibrary = netlib[networkLibrary];
405404
}
406405
else
407406
{
@@ -1098,14 +1097,14 @@ internal SqlConnectionEncryptOption ConvertValueToSqlConnectionEncrypt()
10981097
}
10991098
}
11001099

1101-
static internal Hashtable NetlibMapping()
1100+
static internal Dictionary<string, string> NetlibMapping()
11021101
{
11031102
const int NetLibCount = 8;
11041103

1105-
Hashtable hash = s_netlibMapping;
1104+
Dictionary<string, string> hash = s_netlibMapping;
11061105
if (hash == null)
11071106
{
1108-
hash = new Hashtable(NetLibCount)
1107+
hash = new Dictionary<string, string>(NetLibCount)
11091108
{
11101109
{ NETLIB.TCPIP, TdsEnums.TCP },
11111110
{ NETLIB.NamedPipes, TdsEnums.NP },
@@ -1147,7 +1146,7 @@ internal static class NETLIB
11471146
internal const string VIA = "dbmsgnet";
11481147
}
11491148

1150-
private static Hashtable s_netlibMapping;
1149+
private static Dictionary<string, string> s_netlibMapping;
11511150

11521151
#if NETFRAMEWORK
11531152
protected internal override PermissionSet CreatePermissionSet()

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStaticMethods.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,14 @@ internal static int GetCurrentProcessIdForTdsLoginOnly()
139139
// Pick up the process Id from the current process instead of randomly generating it.
140140
// This would be helpful while tracing application related issues.
141141
int processId;
142+
#if NET
143+
processId = Environment.ProcessId;
144+
#else
142145
using (System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess())
143146
{
144147
processId = p.Id;
145148
}
149+
#endif
146150
System.Threading.Volatile.Write(ref s_currentProcessId, processId);
147151
}
148152
return s_currentProcessId;

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/VirtualSecureModeEnclaveProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
using System.Diagnostics;
88
using System.IO;
99
using System.Net.Http;
10-
using System.Runtime.Serialization.Json;
1110
using System.Security.Cryptography.X509Certificates;
11+
using System.Text.Json;
1212
using System.Threading;
1313

1414
namespace Microsoft.Data.SqlClient
@@ -72,8 +72,7 @@ protected override byte[] MakeRequest(string url)
7272

7373
using (Stream stream = s_client.GetStreamAsync(url).ConfigureAwait(false).GetAwaiter().GetResult())
7474
{
75-
var deserializer = new DataContractJsonSerializer(typeof(byte[]));
76-
return (byte[])deserializer.ReadObject(stream);
75+
return JsonSerializer.Deserialize<List<byte>>(stream)?.ToArray();
7776
}
7877
}
7978
catch (Exception e)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/VirtualSecureModeEnclaveProviderBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private X509Certificate2Collection GetSigningCertificate(string attestationUrl,
202202

203203
try
204204
{
205-
var s = new SignedCms();
205+
SignedCms s = new SignedCms();
206206
s.Decode(data);
207207
certificateCollection.AddRange(s.Certificates);
208208
}

0 commit comments

Comments
 (0)