From 8da9685d9bf3fcd73a775cb7306e4e188cfa214b Mon Sep 17 00:00:00 2001 From: vnugent Date: Mon, 23 Sep 2024 21:54:21 -0400 Subject: feat: scoped spans for forward writer & tests to sln --- lib/Net.Http/src/Core/Request/HttpRequest.cs | 4 ++-- lib/Utils/src/Memory/ForwardOnlyWriter.cs | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/Net.Http/src/Core/Request/HttpRequest.cs b/lib/Net.Http/src/Core/Request/HttpRequest.cs index cbe6bc0..b20427e 100644 --- a/lib/Net.Http/src/Core/Request/HttpRequest.cs +++ b/lib/Net.Http/src/Core/Request/HttpRequest.cs @@ -123,7 +123,7 @@ namespace VNLib.Net.Http.Core private void FreeUploadBuffers() { //Dispose all initialized files, should be much faster than using Array.Clear(); - for (int i = 0; i < _uploads.Length; i++) + for (int i = 0; i < maxUploads; i++) { _uploads[i].Free(); _uploads[i] = default; @@ -136,7 +136,7 @@ namespace VNLib.Net.Http.Core /// Checks if another upload can be added to the request /// /// A value indicating if another file upload can be added to the array - public bool CanAddUpload() => _state.UploadCount < _uploads.Length; + public bool CanAddUpload() => _state.UploadCount < maxUploads; /// /// Attempts to obtain a reference to the next available diff --git a/lib/Utils/src/Memory/ForwardOnlyWriter.cs b/lib/Utils/src/Memory/ForwardOnlyWriter.cs index 55e3b11..947ae18 100644 --- a/lib/Utils/src/Memory/ForwardOnlyWriter.cs +++ b/lib/Utils/src/Memory/ForwardOnlyWriter.cs @@ -82,7 +82,7 @@ namespace VNLib.Utils.Memory /// /// The data sequence to append to the buffer /// - public void Append(ReadOnlySpan data) where TClass : class, T + public void Append(scoped ReadOnlySpan data) where TClass : class, T { //Make sure the current window is large enough to buffer the new string ArgumentOutOfRangeException.ThrowIfGreaterThan(data.Length, RemainingSize, nameof(Remaining)); @@ -101,18 +101,18 @@ namespace VNLib.Utils.Memory /// /// The data sequence to append to the buffer /// - public void Append(ReadOnlySpan data) where TStruct : struct, T + public void Append(scoped ReadOnlySpan data) where TStruct : struct, T { //Make sure the current window is large enough to buffer the new string ArgumentOutOfRangeException.ThrowIfGreaterThan(data.Length, RemainingSize, nameof(Remaining)); //write data to window MemoryUtil.Memmove( - in MemoryMarshal.GetReference(data), - 0, - ref Unsafe.As(ref _basePtr), //Reinterpret the ref to the local scope type, - (nuint)Written, - (nuint)data.Length + src: in MemoryMarshal.GetReference(data), + srcOffset: 0, + dst: ref Unsafe.As(ref _basePtr), //Reinterpret the ref to the local scope type, + dstOffset: (nuint)Written, + elementCount: (nuint)data.Length ); //update char position @@ -127,18 +127,18 @@ namespace VNLib.Utils.Memory /// /// The data sequence to append to the buffer /// - public void AppendSmall(ReadOnlySpan data) where TStruct : struct, T + public void AppendSmall(scoped ReadOnlySpan data) where TStruct : struct, T { //Make sure the current window is large enough to buffer the new string ArgumentOutOfRangeException.ThrowIfGreaterThan(data.Length, RemainingSize, nameof(Remaining)); //write data to window MemoryUtil.SmallMemmove( - in MemoryMarshal.GetReference(data), - 0, - ref Unsafe.As(ref _basePtr), //Reinterpret the ref to the local scope type, - (nuint)Written, - (ushort)data.Length + src: in MemoryMarshal.GetReference(data), + srcOffset: 0, + dst: ref Unsafe.As(ref _basePtr), //Reinterpret the ref to the local scope type, + dstOffset: (nuint)Written, + elementCount: (ushort)data.Length ); //update char position -- cgit