From 50885f7cd7e0519c96b0c95fce9ba6bf69502cf7 Mon Sep 17 00:00:00 2001 From: vnugent Date: Mon, 8 Jan 2024 22:04:41 -0500 Subject: Some net 8.0 goodies like sha3 support --- lib/Plugins.Essentials/src/SemiConsistentVeTable.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'lib/Plugins.Essentials') diff --git a/lib/Plugins.Essentials/src/SemiConsistentVeTable.cs b/lib/Plugins.Essentials/src/SemiConsistentVeTable.cs index 4849107..a235b13 100644 --- a/lib/Plugins.Essentials/src/SemiConsistentVeTable.cs +++ b/lib/Plugins.Essentials/src/SemiConsistentVeTable.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials @@ -26,6 +26,7 @@ using System; using System.Linq; using System.Threading; using System.Threading.Tasks; +using System.Collections.Frozen; using System.Collections.Generic; using VNLib.Net.Http; @@ -60,7 +61,9 @@ namespace VNLib.Plugins.Essentials /// A "lookup table" that represents virtual endpoints to be processed when an /// incomming connection matches its path parameter /// - private IReadOnlyDictionary> VirtualEndpoints = new Dictionary>(StringComparer.OrdinalIgnoreCase); + private FrozenDictionary> VirtualEndpoints = + new Dictionary>(StringComparer.OrdinalIgnoreCase) + .ToFrozenDictionary(); /* @@ -112,15 +115,17 @@ namespace VNLib.Plugins.Essentials newTable.Add(ep.Path, ep); } + FrozenDictionary> newTableFrozen = newTable.ToFrozenDictionary(); + //Store the new table - _ = Interlocked.Exchange(ref VirtualEndpoints, newTable); + _ = Interlocked.Exchange(ref VirtualEndpoints, newTableFrozen); } } /// public void RemoveEndpoint(params IEndpoint[] eps) { - _ = eps ?? throw new ArgumentNullException(nameof(eps)); + ArgumentNullException.ThrowIfNull(eps); //Call remove on path RemoveEndpoint(eps.Select(static s => s.Path).ToArray()); } @@ -128,7 +133,7 @@ namespace VNLib.Plugins.Essentials /// public void RemoveEndpoint(params string[] paths) { - _ = paths ?? throw new ArgumentNullException(nameof(paths)); + ArgumentNullException.ThrowIfNull(paths); //Make sure all endpoints specify a path if (paths.Any(static e => string.IsNullOrWhiteSpace(e))) @@ -152,8 +157,10 @@ namespace VNLib.Plugins.Essentials _ = newTable.Remove(eps); } + FrozenDictionary> newTableFrozen = newTable.ToFrozenDictionary(); + //Store the new table - _ = Interlocked.Exchange(ref VirtualEndpoints, newTable); + _ = Interlocked.Exchange(ref VirtualEndpoints, newTableFrozen); } } -- cgit