aboutsummaryrefslogtreecommitdiff
path: root/lib/Utils/src/Memory/PrivateStringManager.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-09-14 15:54:30 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-09-14 15:54:30 -0400
commitbb706bbfa7519c8b5c506e76a787b9b016acfb75 (patch)
tree12abc5835dc6df87c3aaf7d39dfd541fa26b6529 /lib/Utils/src/Memory/PrivateStringManager.cs
parenta19807f7f73ffb023e4ffe93071fe91525fd2c8d (diff)
Squashed commit of the following:HEADmaster
commit 322bbe00f77772ba6b0e25759de95dd517b6014c Author: vnugent <public@vaughnnugent.com> Date: Sat Sep 14 15:43:45 2024 -0400 build: Testing updates and easier dev-testing commit abcd0e0d6cb5532c8a19a8cd8c7dd83e7f143442 Author: vnugent <public@vaughnnugent.com> Date: Wed Sep 11 16:43:20 2024 -0400 Managed library & package updates commit 2ae018af277b808786cf398c689910bc016e7ef0 Author: vnugent <public@vaughnnugent.com> Date: Tue Sep 10 18:59:06 2024 -0400 fix: zero/unsafezero with data types > sizeof(byte) commit 17c646a619eaa101d66871faa8f57c76500a8ad2 Merge: 97d0c46 a19807f Author: vnugent <public@vaughnnugent.com> Date: Sat Sep 7 15:31:01 2024 -0400 Merge branch 'master' into develop
Diffstat (limited to 'lib/Utils/src/Memory/PrivateStringManager.cs')
-rw-r--r--lib/Utils/src/Memory/PrivateStringManager.cs23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/Utils/src/Memory/PrivateStringManager.cs b/lib/Utils/src/Memory/PrivateStringManager.cs
index 2bc825c..1a7b3cf 100644
--- a/lib/Utils/src/Memory/PrivateStringManager.cs
+++ b/lib/Utils/src/Memory/PrivateStringManager.cs
@@ -61,11 +61,11 @@ namespace VNLib.Utils.Memory
private void SetValue(int index, string? value)
{
//Try to get the old reference and erase it
- StringRef strRef = ProtectedElements[index];
+ ref StringRef strRef = ref ProtectedElements[index];
strRef.Erase();
- //Set the new value and determine if it is interned
- ProtectedElements[index] = StringRef.Create(value);
+ //Assign new string reference
+ strRef = StringRef.Create(value);
}
/// <summary>
@@ -78,7 +78,7 @@ namespace VNLib.Utils.Memory
protected string? CopyStringAtIndex(int index)
{
Check();
- StringRef str = ProtectedElements[index];
+ ref readonly StringRef str = ref ProtectedElements[index];
if(str.Value is null)
{
@@ -101,7 +101,8 @@ namespace VNLib.Utils.Memory
}
///<inheritdoc/>
- protected override void Free() => Array.ForEach(ProtectedElements, static p => p.Erase());
+ protected override void Free()
+ => Array.ForEach(ProtectedElements, static p => p.Erase());
/// <summary>
/// Erases the contents of the supplied string if it
@@ -109,10 +110,14 @@ namespace VNLib.Utils.Memory
/// not be erased, nor will a null string
/// </summary>
/// <param name="str">The reference to the string to zero</param>
- public static void EraseString(string? str) => StringRef.Create(str).Erase();
+ public static void EraseString(string? str)
+ => StringRef.Create(str).Erase();
- private readonly record struct StringRef(string? Value, bool IsInterned)
+ private readonly struct StringRef(string? value, bool isInterned)
{
+ public readonly string? Value = value;
+ public readonly bool IsInterned = isInterned;
+
public readonly void Erase()
{
/*
@@ -125,8 +130,8 @@ namespace VNLib.Utils.Memory
}
}
- internal static StringRef Create(string? str) => str is null ?
- new(null, false)
+ internal static StringRef Create(string? str) => str is null
+ ? new(value: null, isInterned: false)
: new(str, string.IsInterned(str) != null);
}
}