using System.Collections.Generic; using Unity.Properties; namespace Uigenx.Binding { /// /// Caches parsed values. Parsing allocates one substring per segment, /// so anything that resolves a path more than once should go through here. /// public static class UgxPropertyPaths { /// /// Upper bound on cached paths. Paths come from generated code and from the studio, so the /// working set is small; the cap only stops a misbehaving peer from growing the cache. /// public const int MaxCached = 512; static readonly Dictionary Cache = new Dictionary(64); public static PropertyPath Get(string path) { if (string.IsNullOrEmpty(path)) return default; if (Cache.TryGetValue(path, out var cached)) return cached; var parsed = new PropertyPath(path); if (Cache.Count < MaxCached) Cache[path] = parsed; return parsed; } public static void ClearCache() => Cache.Clear(); } }