aboutsummaryrefslogtreecommitdiff
path: root/lib/Utils
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-01-06 13:09:21 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2024-01-06 13:09:21 -0500
commit86c0532edc0042b26dda5f1ca41abdf80db46414 (patch)
treed415be3b7fcf06577e76ee8ff22a3c76c9b65387 /lib/Utils
parentc7cbe768eb153efd61568178b3b9d0b4f50e20a7 (diff)
initial migration to .net 8.0
Diffstat (limited to 'lib/Utils')
-rw-r--r--lib/Utils/README.md2
-rw-r--r--lib/Utils/src/ERRNO.cs10
-rw-r--r--lib/Utils/src/Extensions/StringExtensions.cs22
-rw-r--r--lib/Utils/src/Memory/MemoryUtil.cs12
-rw-r--r--lib/Utils/src/Resources/ResourceDeleteFailedException.cs5
-rw-r--r--lib/Utils/src/Resources/ResourceUpdateFailedException.cs6
-rw-r--r--lib/Utils/src/VNLib.Utils.csproj6
-rw-r--r--lib/Utils/tests/VNLib.UtilsTests.csproj2
8 files changed, 30 insertions, 35 deletions
diff --git a/lib/Utils/README.md b/lib/Utils/README.md
index f5b1244..341b1d4 100644
--- a/lib/Utils/README.md
+++ b/lib/Utils/README.md
@@ -1,6 +1,6 @@
# VNLib.Utils
-A .NET 6 /C# library for common .NET operation and memory optimizations.
+A .NET 8 /C# library for common .NET operation and memory optimizations.
### Builds & Feeds
Builds contain the individual components listed below packaged per-project, available for download on my website. Build packages will be tgz archives (except for nuget packages). You can obtain debug and release builds, along with per-project source code.
diff --git a/lib/Utils/src/ERRNO.cs b/lib/Utils/src/ERRNO.cs
index 3bc1296..2a59ba6 100644
--- a/lib/Utils/src/ERRNO.cs
+++ b/lib/Utils/src/ERRNO.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Utils
@@ -85,13 +85,7 @@ namespace VNLib.Utils
/// C style boolean conversion. false if 0, true otherwise
/// </summary>
/// <param name="errorVal"></param>
- public static implicit operator bool(ERRNO errorVal) => errorVal != 0;
-
- /// <summary>
- /// Creates a new <see cref="IntPtr"/> from the value if the stored (nint) error code
- /// </summary>
- /// <param name="errno">The <see cref="ERRNO"/> contating the pointer value</param>
- public static implicit operator IntPtr(ERRNO errno) => new(errno.ErrorCode);
+ public static implicit operator bool(ERRNO errorVal) => errorVal != 0;
/// <summary>
/// Creates a new <c>nint</c> from the value if the stored error code
diff --git a/lib/Utils/src/Extensions/StringExtensions.cs b/lib/Utils/src/Extensions/StringExtensions.cs
index 42b7b32..7ffaaa2 100644
--- a/lib/Utils/src/Extensions/StringExtensions.cs
+++ b/lib/Utils/src/Extensions/StringExtensions.cs
@@ -475,10 +475,10 @@ namespace VNLib.Utils.Extensions
{
Span<char> buffer = writer.AsSpan();
- //If the search and replacment parameters are the same length
+ //If the search and replacement parameters are the same length
if (search.Length == replace.Length)
{
- buffer.ReplaceInPlace(search, replace);
+ ReplaceInPlace(buffer, search, replace);
return;
}
@@ -490,24 +490,28 @@ namespace VNLib.Utils.Extensions
return;
}
- //Replacment might be empty
- writer.Reset();
+ //Init new writer over the buffer
+ ForwardOnlyWriter<char> writer2 = new(buffer);
do
{
- //Append the data before the split character
- writer.Append(buffer[..start]);
+ //Append the data before the search chars
+ writer2.Append(buffer[..start]);
//Append the replacment
- writer.Append(replace);
+ writer2.Append(replace);
//Shift buffer to the end of the
buffer = buffer[(start + searchLen)..];
- //search for next index
+ //search for next index beyond current index
start = buffer.IndexOf(search);
} while (start > -1);
//Write remaining data
- writer.Append(replace);
+ writer2.Append(replace);
+
+ //Reset writer1 and advance it to the end of writer2
+ writer.Reset();
+ writer.Advance(writer2.Written);
}
/// <summary>
diff --git a/lib/Utils/src/Memory/MemoryUtil.cs b/lib/Utils/src/Memory/MemoryUtil.cs
index 02d2f0e..1e0d11a 100644
--- a/lib/Utils/src/Memory/MemoryUtil.cs
+++ b/lib/Utils/src/Memory/MemoryUtil.cs
@@ -280,12 +280,12 @@ namespace VNLib.Utils.Memory
{
Debug.Assert(Unsafe.IsNullRef(ref src) == false, "Null reference passed to ZeroByRef");
- //Convert to bytes
- uint byteSize = ByteCount<T>(elements);
- ref byte byteRef = ref Unsafe.As<T, byte>(ref src);
-
- //Call init block
- Unsafe.InitBlock(ref byteRef, 0, byteSize);
+ //Call init block on bytes
+ Unsafe.InitBlock(
+ ref Refs.AsByte(ref src, 0),
+ 0,
+ ByteCount<T>(elements)
+ );
}
/*
diff --git a/lib/Utils/src/Resources/ResourceDeleteFailedException.cs b/lib/Utils/src/Resources/ResourceDeleteFailedException.cs
index 8e796b5..499442c 100644
--- a/lib/Utils/src/Resources/ResourceDeleteFailedException.cs
+++ b/lib/Utils/src/Resources/ResourceDeleteFailedException.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Utils
@@ -23,7 +23,7 @@
*/
using System;
-using System.Runtime.Serialization;
+
namespace VNLib.Utils.Resources
{
@@ -35,6 +35,5 @@ namespace VNLib.Utils.Resources
public ResourceDeleteFailedException() { }
public ResourceDeleteFailedException(string message) : base(message) { }
public ResourceDeleteFailedException(string message, Exception innerException) : base(message, innerException) { }
- protected ResourceDeleteFailedException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
} \ No newline at end of file
diff --git a/lib/Utils/src/Resources/ResourceUpdateFailedException.cs b/lib/Utils/src/Resources/ResourceUpdateFailedException.cs
index b4b2b3a..447dc2e 100644
--- a/lib/Utils/src/Resources/ResourceUpdateFailedException.cs
+++ b/lib/Utils/src/Resources/ResourceUpdateFailedException.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Utils
@@ -23,7 +23,6 @@
*/
using System;
-using System.Runtime.Serialization;
namespace VNLib.Utils.Resources
{
@@ -35,6 +34,5 @@ namespace VNLib.Utils.Resources
public ResourceUpdateFailedException() { }
public ResourceUpdateFailedException(string message) : base(message) { }
public ResourceUpdateFailedException(string message, Exception innerException) : base(message, innerException) { }
- protected ResourceUpdateFailedException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
-} \ No newline at end of file
+}
diff --git a/lib/Utils/src/VNLib.Utils.csproj b/lib/Utils/src/VNLib.Utils.csproj
index d121183..54199e0 100644
--- a/lib/Utils/src/VNLib.Utils.csproj
+++ b/lib/Utils/src/VNLib.Utils.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFramework>net6.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<RootNamespace>VNLib.Utils</RootNamespace>
<AssemblyName>VNLib.Utils</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -16,8 +16,8 @@
<Authors>Vaughn Nugent</Authors>
<Company>Vaughn Nugent</Company>
<Product>VNLib Utilities Library</Product>
- <Copyright>Copyright © 2023 Vaughn Nugent</Copyright>
- <Description>.NET/6.0 Utilities library for high-performance common operations. Utilities and abstractions for building and diagnosing native memory implementations. Dyanmic native library loading, IO, extensions, data encoding, resource access, and asynchronous cooperation primitives.</Description>
+ <Copyright>Copyright © 2024 Vaughn Nugent</Copyright>
+ <Description>.NET/8.0 Utilities library for high-performance common operations. Utilities and abstractions for building and diagnosing native memory implementations. Dyanmic native library loading, IO, extensions, data encoding, resource access, and asynchronous cooperation primitives.</Description>
<PackageProjectUrl>https://www.vaughnnugent.com/resources/software/modules/VNLib.Core</PackageProjectUrl>
<RepositoryUrl>https://github.com/VnUgE/VNLib.Core/tree/main/lib/Utils</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
diff --git a/lib/Utils/tests/VNLib.UtilsTests.csproj b/lib/Utils/tests/VNLib.UtilsTests.csproj
index f8cb807..6a8a065 100644
--- a/lib/Utils/tests/VNLib.UtilsTests.csproj
+++ b/lib/Utils/tests/VNLib.UtilsTests.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFramework>net6.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>