From b85243e0d263847b6915acf08942932ca8cd49f8 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 25 Aug 2020 16:09:25 +0100 Subject: [PATCH 1/3] Bump ChunkedMemoryStream buffer length --- README.md | 2 +- src/ImageSharp/IO/ChunkedMemoryStream.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index adf9647cc..6b2fa5d0f 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Install stable releases via Nuget; development releases are available via MyGet. | Package Name | Release (NuGet) | Nightly (MyGet) | |--------------------------------|-----------------|-----------------| -| `SixLabors.ImageSharp` | [![NuGet](https://img.shields.io/nuget/v/SixLabors.ImageSharp.svg)](https://www.nuget.org/packages/SixLabors.ImageSharp/) | [![MyGet](https://img.shields.io/myget/sixlabors/v/SixLabors.ImageSharp.svg)](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp) | +| `SixLabors.ImageSharp` | [![NuGet](https://img.shields.io/nuget/v/SixLabors.ImageSharp.svg)](https://www.nuget.org/packages/SixLabors.ImageSharp/) | [![MyGet](https://img.shields.io/myget/sixlabors/vpre/SixLabors.ImageSharp.svg)](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp) | ## Manual build diff --git a/src/ImageSharp/IO/ChunkedMemoryStream.cs b/src/ImageSharp/IO/ChunkedMemoryStream.cs index 2d895245c..9a2d75276 100644 --- a/src/ImageSharp/IO/ChunkedMemoryStream.cs +++ b/src/ImageSharp/IO/ChunkedMemoryStream.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.IO /// /// The default length in bytes of each buffer chunk. /// - public const int DefaultBufferLength = 81920; + public const int DefaultBufferLength = 128 * 1024; // The memory allocator. private readonly MemoryAllocator allocator; From 29d133c89a189fdaf56c35641b5f18447aa97796 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 25 Aug 2020 17:39:52 +0100 Subject: [PATCH 2/3] Fix build --- .github/workflows/build-and-test.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index a83e19423..412b1d807 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -52,11 +52,6 @@ jobs: git fetch --prune --unshallow git submodule -q update --init --recursive - - name: Setup DotNet SDK - uses: actions/setup-dotnet@v1 - with: - dotnet-version: "3.1.x" - - name: Build shell: pwsh run: ./ci-build.ps1 "${{matrix.options.framework}}" @@ -95,11 +90,6 @@ jobs: git fetch --prune --unshallow git submodule -q update --init --recursive - - name: Setup DotNet SDK - uses: actions/setup-dotnet@v1 - with: - dotnet-version: "3.1.x" - - name: Pack shell: pwsh run: ./ci-pack.ps1 From 6d90af1a8bcdc53228f714fbe63c9d0e8319849d Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 25 Aug 2020 19:26:30 +0100 Subject: [PATCH 3/3] Remove Guard allocations --- src/ImageSharp/IO/ChunkedMemoryStream.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/IO/ChunkedMemoryStream.cs b/src/ImageSharp/IO/ChunkedMemoryStream.cs index 9a2d75276..c5fc6b939 100644 --- a/src/ImageSharp/IO/ChunkedMemoryStream.cs +++ b/src/ImageSharp/IO/ChunkedMemoryStream.cs @@ -238,7 +238,9 @@ namespace SixLabors.ImageSharp.IO Guard.NotNull(buffer, nameof(buffer)); Guard.MustBeGreaterThanOrEqualTo(offset, 0, nameof(offset)); Guard.MustBeGreaterThanOrEqualTo(count, 0, nameof(count)); - Guard.IsFalse(buffer.Length - offset < count, nameof(buffer), $"{offset} subtracted from the buffer length is less than {count}"); + + const string BufferMessage = "Offset subtracted from the buffer length is less than count."; + Guard.IsFalse(buffer.Length - offset < count, nameof(buffer), BufferMessage); return this.ReadImpl(buffer.AsSpan().Slice(offset, count)); } @@ -348,7 +350,16 @@ namespace SixLabors.ImageSharp.IO /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public override void Write(byte[] buffer, int offset, int count) - => this.WriteImpl(buffer.AsSpan().Slice(offset, count)); + { + Guard.NotNull(buffer, nameof(buffer)); + Guard.MustBeGreaterThanOrEqualTo(offset, 0, nameof(offset)); + Guard.MustBeGreaterThanOrEqualTo(count, 0, nameof(count)); + + const string BufferMessage = "Offset subtracted from the buffer length is less than count."; + Guard.IsFalse(buffer.Length - offset < count, nameof(buffer), BufferMessage); + + this.WriteImpl(buffer.AsSpan().Slice(offset, count)); + } #if SUPPORTS_SPAN_STREAM ///