Skip to content

Commit d7462c0

Browse files
committed
remove debug only uses of linq
1 parent 263f82e commit d7462c0

File tree

4 files changed

+78
-22
lines changed

4 files changed

+78
-22
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIPhysicalHandle.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
using System;
66
using System.Diagnostics;
77
using System.Threading;
8-
#if DEBUG
9-
using System.Linq;
10-
#endif
8+
using System.Collections.Generic;
119

1210
namespace Microsoft.Data.SqlClient.SNI
1311
{
@@ -85,12 +83,19 @@ public override void ReturnPacket(SNIPacket packet)
8583
#if DEBUG
8684
private string GetStackParts()
8785
{
88-
return string.Join(Environment.NewLine,
89-
Environment.StackTrace
90-
.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)
91-
.Skip(3) // trims off the common parts at the top of the stack so you can see what the actual caller was
92-
.Take(7) // trims off most of the bottom of the stack because when running under xunit there's a lot of spam
93-
);
86+
// trims off the common parts at the top of the stack so you can see what the actual caller was
87+
// trims off most of the bottom of the stack because when running under xunit there's a lot of spam
88+
string[] parts = Environment.StackTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
89+
List<string> take = new List<string>(7);
90+
for (int index = 0; take.Count < 7 && index < parts.Length; index++)
91+
{
92+
if (index > 2)
93+
{
94+
take.Add(parts[index]);
95+
}
96+
}
97+
98+
return string.Join(Environment.NewLine, take.ToArray());
9499
}
95100
#endif
96101
}

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Common/DBConnectionString.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ namespace Microsoft.Data.Common
99
using System.Collections.Generic;
1010
using System.Data;
1111
using System.Diagnostics;
12-
#if DEBUG
13-
using System.Linq;
14-
#endif
1512
using System.Text;
1613
using Microsoft.Data.SqlClient;
1714

@@ -312,7 +309,12 @@ private void ValidateCombinedSet(DBConnectionString componentSet, DBConnectionSt
312309
// Component==Allow, Combined==Allow
313310
// All values in the Combined Set should also be in the Component Set
314311
// Combined - Component == null
315-
Debug.Assert(combinedSet._restrictionValues.Except(componentSet._restrictionValues).Count() == 0, "Combined set allows values not allowed by component set");
312+
#if DEBUG
313+
HashSet<string> combined = new HashSet<string>(combinedSet._restrictionValues);
314+
HashSet<string> component = new HashSet<string>(componentSet._restrictionValues);
315+
combined.ExceptWith(component);
316+
Debug.Assert(combined.Count == 0, "Combined set allows values not allowed by component set");
317+
#endif
316318
}
317319
else if (combinedSet._behavior == KeyRestrictionBehavior.PreventUsage)
318320
{
@@ -331,14 +333,24 @@ private void ValidateCombinedSet(DBConnectionString componentSet, DBConnectionSt
331333
// Component==PreventUsage, Combined==Allow
332334
// There shouldn't be any of the values from the Component Set in the Combined Set
333335
// Intersect(Component, Combined) == null
334-
Debug.Assert(combinedSet._restrictionValues.Intersect(componentSet._restrictionValues).Count() == 0, "Combined values allows values prevented by component set");
336+
#if DEBUG
337+
HashSet<string> combined = new HashSet<string>(combinedSet._restrictionValues);
338+
HashSet<string> component = new HashSet<string>(componentSet._restrictionValues);
339+
combined.IntersectWith(component);
340+
Debug.Assert(combined.Count == 0, "Combined values allows values prevented by component set");
341+
#endif
335342
}
336343
else if (combinedSet._behavior == KeyRestrictionBehavior.PreventUsage)
337344
{
338345
// Component==PreventUsage, Combined==PreventUsage
339346
// All values in the Component Set should also be in the Combined Set
340347
// Component - Combined == null
341-
Debug.Assert(componentSet._restrictionValues.Except(combinedSet._restrictionValues).Count() == 0, "Combined values does not prevent all of the values prevented by the component set");
348+
#if DEBUG
349+
HashSet<string> combined = new HashSet<string>(combinedSet._restrictionValues);
350+
HashSet<string> component = new HashSet<string>(componentSet._restrictionValues);
351+
component.IntersectWith(combined);
352+
Debug.Assert(component.Count == 0, "Combined values does not prevent all of the values prevented by the component set");
353+
#endif
342354
}
343355
else
344356
{

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Diagnostics;
8-
#if DEBUG
9-
using System.Linq;
10-
#endif
118
using System.Runtime.CompilerServices;
129
using System.Runtime.ConstrainedExecution;
1310
using System.Runtime.InteropServices;
@@ -3336,7 +3333,16 @@ internal void CloneCleanupAltMetaDataSetArray()
33363333
internal void PushBuffer(byte[] buffer, int read)
33373334
{
33383335
#if DEBUG
3339-
Debug.Assert(!_snapshotInBuffs.Any(b => object.ReferenceEquals(b, buffer)));
3336+
if (_snapshotInBuffs != null && _snapshotInBuffs.Count > 0)
3337+
{
3338+
foreach (PacketData packet in _snapshotInBuffs)
3339+
{
3340+
if (object.ReferenceEquals(packet.Buffer, buffer))
3341+
{
3342+
Debug.Assert(false,"buffer is already present in packet list");
3343+
}
3344+
}
3345+
}
33403346
#endif
33413347
PacketData packetData = new PacketData();
33423348
packetData.Buffer = buffer;

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

Lines changed: 36 additions & 3 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.Linq;
76
using System.Runtime.Caching;
87
using System.Security.Cryptography;
98
using System.Security.Cryptography.X509Certificates;
@@ -220,7 +219,17 @@ private X509Certificate2Collection GetSigningCertificate(string attestationUrl,
220219
// Checks if any certificates in the collection are expired
221220
private bool AnyCertificatesExpired(X509Certificate2Collection certificates)
222221
{
223-
return certificates.OfType<X509Certificate2>().Any(c => c.NotAfter < DateTime.Now);
222+
if (certificates != null)
223+
{
224+
foreach (object item in certificates)
225+
{
226+
if (item is X509Certificate2 certificate && certificate.NotAfter < DateTime.Now)
227+
{
228+
return true;
229+
}
230+
}
231+
}
232+
return false;
224233
}
225234

226235
// Verifies that a chain of trust can be built from the health report provided
@@ -325,7 +334,31 @@ private void VerifyEnclavePolicy(EnclaveReportPackage enclaveReportPackage)
325334
// Verifies a byte[] enclave policy property
326335
private void VerifyEnclavePolicyProperty(string property, byte[] actual, byte[] expected)
327336
{
328-
if (!actual.SequenceEqual(expected))
337+
bool different = false;
338+
if (actual == null || expected == null)
339+
{
340+
different = true;
341+
}
342+
else
343+
{
344+
if (actual.Length != expected.Length)
345+
{
346+
different = true;
347+
}
348+
else
349+
{
350+
for (int index = 0; index < actual.Length; index++)
351+
{
352+
if (actual[index] != expected[index])
353+
{
354+
different = true;
355+
break;
356+
}
357+
}
358+
}
359+
}
360+
361+
if (different)
329362
{
330363
string exceptionMessage = String.Format(Strings.VerifyEnclavePolicyFailedFormat, property, BitConverter.ToString(actual), BitConverter.ToString(expected));
331364
throw new ArgumentException(exceptionMessage);

0 commit comments

Comments
 (0)