Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/NerdBank.GitVersioning/ManagedGit/GitPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GitPack : IDisposable

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public override long Position
set => throw new NotImplementedException();
}

#if NETSTANDARD
#if NETSTANDARD2_0
/// <summary>
/// Reads a sequence of bytes from the current <see cref="GitPackDeltafiedStream"/> and advances the position
/// within the stream by the number of bytes read.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override void Flush()
throw new NotSupportedException();
}

#if NETSTANDARD
#if NETSTANDARD2_0
public int Read(Span<byte> buffer)
#else
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override int Read(byte[] buffer, int offset, int count)
return this.Read(buffer.AsSpan(offset, count));
}

#if NETSTANDARD
#if NETSTANDARD2_0
public int Read(Span<byte> buffer)
#else
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override void Flush()
this.stream.Flush();
}

#if !NETSTANDARD
#if !NETSTANDARD2_0
/// <inheritdoc/>
public override int Read(Span<byte> buffer)
{
Expand Down
10 changes: 5 additions & 5 deletions src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GitRepository : IDisposable

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

#if DEBUG && !NETSTANDARD
#if DEBUG
private Dictionary<GitObjectId, int> histogram = new Dictionary<GitObjectId, int>();
#endif

Expand Down Expand Up @@ -524,7 +524,7 @@ public GitObjectId GetTreeEntry(GitObjectId treeId, ReadOnlySpan<byte> nodeName)
/// </returns>
public bool TryGetObjectBySha(GitObjectId sha, string objectType, out Stream? value)
{
#if DEBUG && !NETSTANDARD
#if DEBUG
if (!this.histogram.TryAdd(sha, 1))
{
this.histogram[sha] += 1;
Expand Down Expand Up @@ -566,7 +566,7 @@ public string GetCacheStatistics()
{
StringBuilder builder = new StringBuilder();

#if DEBUG && !NETSTANDARD
#if DEBUG
int histogramCount = 25;

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

private static string TrimEndingDirectorySeparator(string path)
{
#if NETSTANDARD
#if NETSTANDARD2_0
if (string.IsNullOrEmpty(path) || path.Length == 1)
{
return path;
Expand Down Expand Up @@ -690,7 +690,7 @@ private static bool TryConvertHexStringToByteArray(string hexString, Span<byte>
Requires.Argument(data.Length == hexString.Length / 2, nameof(data), "Length must be exactly half that of " + nameof(hexString) + ".");
for (int index = 0; index < data.Length; index++)
{
#if NETCOREAPP3_1_OR_GREATER
#if !NETSTANDARD2_0
ReadOnlySpan<char> byteValue = hexString.AsSpan(index * 2, 2);
if (!byte.TryParse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out data[index]))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override int Read(byte[] buffer, int offset, int count)
return read;
}

#if !NETSTANDARD
#if !NETSTANDARD2_0
/// <inheritdoc/>
public override int Read(Span<byte> buffer)
{
Expand Down
14 changes: 12 additions & 2 deletions src/NerdBank.GitVersioning/ManagedGit/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Buffers;
using System.Diagnostics;
using System.IO;

namespace Nerdbank.GitVersioning.ManagedGit
Expand Down Expand Up @@ -78,7 +77,7 @@ public static int ReadMbsInt(this Stream stream)
return value;
}

#if NETSTANDARD
#if NETSTANDARD2_0
/// <summary>
/// Reads a sequence of bytes from the current stream and advances the position within the stream by
/// the number of bytes read.
Expand Down Expand Up @@ -139,6 +138,17 @@ public static void Write(this Stream stream, Span<byte> span)
ArrayPool<byte>.Shared.Return(buffer);
}
}

internal static bool TryAdd<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
{
if (dictionary.ContainsKey(key))
{
return false;
}

dictionary.Add(key, value);
return true;
}
#endif
}
}
4 changes: 2 additions & 2 deletions src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override int Read(byte[] array, int offset, int count)
return read;
}

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

#if !NETSTANDARD
#if !NETSTANDARD2_0
/// <inheritdoc/>
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
{
Expand Down