diff --git a/eng/Versions.props b/eng/Versions.props index 6c958b9372..88c583135e 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -12,7 +12,7 @@ - 3.0.100-preview5-011317 + 3.0.100-preview5-011462 2.2.0 2.2.1 2.0.0 diff --git a/global.json b/global.json index c55a15b7c7..c0fafda3c0 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "tools": { - "dotnet": "3.0.100-preview5-011317" + "dotnet": "3.0.100-preview5-011462" }, "msbuild-sdks": { "Microsoft.DotNet.Arcade.Sdk": "1.0.0-beta.19218.1" diff --git a/src/dotnet/ToolManifest/ArrayBufferWriter.cs b/src/dotnet/ToolManifest/ArrayBufferWriter.cs deleted file mode 100644 index e72d19f4e8..0000000000 --- a/src/dotnet/ToolManifest/ArrayBufferWriter.cs +++ /dev/null @@ -1,182 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Buffers; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -// TODO Remove once we have https://github.com/dotnet/corefx/issues/34894 - -namespace Microsoft.DotNet.Cli.Utils -{ - // Note: this is an internal class that will be replaced with a shared version. - internal sealed class ArrayBufferWriter : IBufferWriter, IDisposable - { - private T[] _rentedBuffer; - private int _index; - - private const int MinimumBufferSize = 256; - - public ArrayBufferWriter() - { - _rentedBuffer = ArrayPool.Shared.Rent(MinimumBufferSize); - _index = 0; - } - - public ArrayBufferWriter(int initialCapacity) - { - if (initialCapacity <= 0) - throw new ArgumentException(nameof(initialCapacity)); - - _rentedBuffer = ArrayPool.Shared.Rent(initialCapacity); - _index = 0; - } - - public ReadOnlyMemory WrittenMemory - { - get - { - CheckIfDisposed(); - - return _rentedBuffer.AsMemory(0, _index); - } - } - - public int WrittenCount - { - get - { - CheckIfDisposed(); - - return _index; - } - } - - public int Capacity - { - get - { - CheckIfDisposed(); - - return _rentedBuffer.Length; - } - } - - public int FreeCapacity - { - get - { - CheckIfDisposed(); - - return _rentedBuffer.Length - _index; - } - } - - public void Clear() - { - CheckIfDisposed(); - - ClearHelper(); - } - - private void ClearHelper() - { - Debug.Assert(_rentedBuffer != null); - - _rentedBuffer.AsSpan(0, _index).Clear(); - _index = 0; - } - - // Returns the rented buffer back to the pool - public void Dispose() - { - if (_rentedBuffer == null) - { - return; - } - - ClearHelper(); - ArrayPool.Shared.Return(_rentedBuffer); - _rentedBuffer = null; - } - - private void CheckIfDisposed() - { - if (_rentedBuffer == null) - throw new ObjectDisposedException(nameof(ArrayBufferWriter)); - } - - public void Advance(int count) - { - CheckIfDisposed(); - - if (count < 0) - throw new ArgumentException(nameof(count)); - - if (_index > _rentedBuffer.Length - count) - ThrowInvalidOperationException(_rentedBuffer.Length); - - _index += count; - } - - public Memory GetMemory(int sizeHint = 0) - { - CheckIfDisposed(); - - CheckAndResizeBuffer(sizeHint); - return _rentedBuffer.AsMemory(_index); - } - - public Span GetSpan(int sizeHint = 0) - { - CheckIfDisposed(); - - CheckAndResizeBuffer(sizeHint); - return _rentedBuffer.AsSpan(_index); - } - - private void CheckAndResizeBuffer(int sizeHint) - { - Debug.Assert(_rentedBuffer != null); - - if (sizeHint < 0) - throw new ArgumentException(nameof(sizeHint)); - - if (sizeHint == 0) - { - sizeHint = MinimumBufferSize; - } - - int availableSpace = _rentedBuffer.Length - _index; - - if (sizeHint > availableSpace) - { - int growBy = Math.Max(sizeHint, _rentedBuffer.Length); - - int newSize = checked(_rentedBuffer.Length + growBy); - - T[] oldBuffer = _rentedBuffer; - - _rentedBuffer = ArrayPool.Shared.Rent(newSize); - - Debug.Assert(oldBuffer.Length >= _index); - Debug.Assert(_rentedBuffer.Length >= _index); - - Span previousBuffer = oldBuffer.AsSpan(0, _index); - previousBuffer.CopyTo(_rentedBuffer); - previousBuffer.Clear(); - ArrayPool.Shared.Return(oldBuffer); - } - - Debug.Assert(_rentedBuffer.Length - _index > 0); - Debug.Assert(_rentedBuffer.Length - _index >= sizeHint); - } - - private static void ThrowInvalidOperationException(int capacity) - { - throw new InvalidOperationException($"Cannot advance past the end of the buffer, which has a size of { capacity }"); - } - } -} diff --git a/src/dotnet/ToolManifest/ToolManifestEditor.cs b/src/dotnet/ToolManifest/ToolManifestEditor.cs index 1c9bafd4fb..38ee22ad0c 100644 --- a/src/dotnet/ToolManifest/ToolManifestEditor.cs +++ b/src/dotnet/ToolManifest/ToolManifestEditor.cs @@ -15,6 +15,7 @@ using NuGet.Versioning; using System.Text.Json; using System.Text; +using System.Buffers; namespace Microsoft.DotNet.ToolManifest { @@ -75,7 +76,8 @@ public void Add( deserializedManifest.Tools.Add( new SerializableLocalToolSinglePackage - { PackageId = packageId.ToString(), + { + PackageId = packageId.ToString(), Version = nuGetVersion.ToNormalizedString(), Commands = toolCommandNames.Select(c => c.Value).ToArray() }); @@ -359,10 +361,9 @@ private class SerializableLocalToolsManifest public string ToJson() { - var state = new JsonWriterState(options: new JsonWriterOptions { Indented = true }); - using (var arrayBufferWriter = new ArrayBufferWriter()) + var arrayBufferWriter = new ArrayBufferWriter(); + using (var writer = new Utf8JsonWriter(arrayBufferWriter, new JsonWriterOptions { Indented = true })) { - var writer = new Utf8JsonWriter(arrayBufferWriter, state); writer.WriteStartObject(); @@ -394,7 +395,7 @@ public string ToJson() writer.WriteEndObject(); writer.WriteEndObject(); - writer.Flush(true); + writer.Flush(); return Encoding.UTF8.GetString(arrayBufferWriter.WrittenMemory.ToArray()); }