Cache S7 variable names

This commit is contained in:
Peter Butzhammer
2024-02-06 13:39:55 +01:00
parent 49fe1968d9
commit 9b0749baae
5 changed files with 34 additions and 27 deletions

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Concurrent;
using Sharp7.Rx.Interfaces;
namespace Sharp7.Rx
{
internal class CacheVariableNameParser : IS7VariableNameParser
{
private static readonly ConcurrentDictionary<string, S7VariableAddress> addressCache = new ConcurrentDictionary<string, S7VariableAddress>(StringComparer.OrdinalIgnoreCase);
private readonly IS7VariableNameParser inner;
public CacheVariableNameParser(IS7VariableNameParser inner)
{
this.inner = inner;
}
public S7VariableAddress Parse(string input) => addressCache.GetOrAdd(input, inner.Parse);
}
}