Skip to content

Commit 9c1d6c6

Browse files
authored
Merge pull request #661 from dotnet/preprocessorChanges
Revise the preprocessor symbols we use
2 parents 115681f + f2f5228 commit 9c1d6c6

9 files changed

+27
-17
lines changed

src/NerdBank.GitVersioning/ManagedGit/GitPack.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class GitPack : IDisposable
3939

4040
// A histogram which tracks the objects which have been retrieved from this GitPack. The key is the offset
4141
// of the object. Used to get some insights in usage patterns.
42-
#if DEBUG && !NETSTANDARD
42+
#if DEBUG
4343
private readonly Dictionary<long, int> histogram = new Dictionary<long, int>();
4444
#endif
4545

@@ -172,7 +172,7 @@ public bool TryGetObject(GitObjectId objectId, string objectType, out Stream? va
172172
/// </returns>
173173
public Stream GetObject(long offset, string objectType)
174174
{
175-
#if DEBUG && !NETSTANDARD
175+
#if DEBUG
176176
if (!this.histogram.TryAdd(offset, 1))
177177
{
178178
this.histogram[offset] += 1;
@@ -230,7 +230,7 @@ public void GetCacheStatistics(StringBuilder builder)
230230
{
231231
builder.AppendLine($"Git Pack:");
232232

233-
#if DEBUG && !NETSTANDARD
233+
#if DEBUG
234234
int histogramCount = 25;
235235
builder.AppendLine($"Top {histogramCount} / {this.histogram.Count} items:");
236236

src/NerdBank.GitVersioning/ManagedGit/GitPackDeltafiedStream.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public override long Position
6464
set => throw new NotImplementedException();
6565
}
6666

67-
#if NETSTANDARD
67+
#if NETSTANDARD2_0
6868
/// <summary>
6969
/// Reads a sequence of bytes from the current <see cref="GitPackDeltafiedStream"/> and advances the position
7070
/// within the stream by the number of bytes read.

src/NerdBank.GitVersioning/ManagedGit/GitPackMemoryCacheStream.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override void Flush()
3737
throw new NotSupportedException();
3838
}
3939

40-
#if NETSTANDARD
40+
#if NETSTANDARD2_0
4141
public int Read(Span<byte> buffer)
4242
#else
4343
/// <inheritdoc/>

src/NerdBank.GitVersioning/ManagedGit/GitPackMemoryCacheViewStream.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override int Read(byte[] buffer, int offset, int count)
3737
return this.Read(buffer.AsSpan(offset, count));
3838
}
3939

40-
#if NETSTANDARD
40+
#if NETSTANDARD2_0
4141
public int Read(Span<byte> buffer)
4242
#else
4343
/// <inheritdoc/>

src/NerdBank.GitVersioning/ManagedGit/GitPackPooledStream.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override void Flush()
6262
this.stream.Flush();
6363
}
6464

65-
#if !NETSTANDARD
65+
#if !NETSTANDARD2_0
6666
/// <inheritdoc/>
6767
public override int Read(Span<byte> buffer)
6868
{

src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class GitRepository : IDisposable
2828

2929
private readonly List<GitRepository> alternates = new List<GitRepository>();
3030

31-
#if DEBUG && !NETSTANDARD
31+
#if DEBUG
3232
private Dictionary<GitObjectId, int> histogram = new Dictionary<GitObjectId, int>();
3333
#endif
3434

@@ -524,7 +524,7 @@ public GitObjectId GetTreeEntry(GitObjectId treeId, ReadOnlySpan<byte> nodeName)
524524
/// </returns>
525525
public bool TryGetObjectBySha(GitObjectId sha, string objectType, out Stream? value)
526526
{
527-
#if DEBUG && !NETSTANDARD
527+
#if DEBUG
528528
if (!this.histogram.TryAdd(sha, 1))
529529
{
530530
this.histogram[sha] += 1;
@@ -566,7 +566,7 @@ public string GetCacheStatistics()
566566
{
567567
StringBuilder builder = new StringBuilder();
568568

569-
#if DEBUG && !NETSTANDARD
569+
#if DEBUG
570570
int histogramCount = 25;
571571

572572
builder.AppendLine("Overall repository:");
@@ -659,7 +659,7 @@ private ReadOnlyMemory<GitPack> LoadPacks()
659659

660660
private static string TrimEndingDirectorySeparator(string path)
661661
{
662-
#if NETSTANDARD
662+
#if NETSTANDARD2_0
663663
if (string.IsNullOrEmpty(path) || path.Length == 1)
664664
{
665665
return path;
@@ -690,7 +690,7 @@ private static bool TryConvertHexStringToByteArray(string hexString, Span<byte>
690690
Requires.Argument(data.Length == hexString.Length / 2, nameof(data), "Length must be exactly half that of " + nameof(hexString) + ".");
691691
for (int index = 0; index < data.Length; index++)
692692
{
693-
#if NETCOREAPP3_1_OR_GREATER
693+
#if !NETSTANDARD2_0
694694
ReadOnlySpan<char> byteValue = hexString.AsSpan(index * 2, 2);
695695
if (!byte.TryParse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out data[index]))
696696
{

src/NerdBank.GitVersioning/ManagedGit/MemoryMappedStream.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public override int Read(byte[] buffer, int offset, int count)
7272
return read;
7373
}
7474

75-
#if !NETSTANDARD
75+
#if !NETSTANDARD2_0
7676
/// <inheritdoc/>
7777
public override int Read(Span<byte> buffer)
7878
{

src/NerdBank.GitVersioning/ManagedGit/StreamExtensions.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
using System;
44
using System.Buffers;
5-
using System.Diagnostics;
65
using System.IO;
76

87
namespace Nerdbank.GitVersioning.ManagedGit
@@ -78,7 +77,7 @@ public static int ReadMbsInt(this Stream stream)
7877
return value;
7978
}
8079

81-
#if NETSTANDARD
80+
#if NETSTANDARD2_0
8281
/// <summary>
8382
/// Reads a sequence of bytes from the current stream and advances the position within the stream by
8483
/// the number of bytes read.
@@ -139,6 +138,17 @@ public static void Write(this Stream stream, Span<byte> span)
139138
ArrayPool<byte>.Shared.Return(buffer);
140139
}
141140
}
141+
142+
internal static bool TryAdd<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
143+
{
144+
if (dictionary.ContainsKey(key))
145+
{
146+
return false;
147+
}
148+
149+
dictionary.Add(key, value);
150+
return true;
151+
}
142152
#endif
143153
}
144154
}

src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public override int Read(byte[] array, int offset, int count)
9494
return read;
9595
}
9696

97-
#if !NETSTANDARD
97+
#if !NETSTANDARD2_0
9898
/// <inheritdoc/>
9999
public override int Read(Span<byte> buffer)
100100
{
@@ -112,7 +112,7 @@ public override async Task<int> ReadAsync(byte[] array, int offset, int count, C
112112
return read;
113113
}
114114

115-
#if !NETSTANDARD
115+
#if !NETSTANDARD2_0
116116
/// <inheritdoc/>
117117
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
118118
{

0 commit comments

Comments
 (0)