using System; using System.Collections.Generic; namespace MLEM.Extensions { /// /// A set of extensions for dealing with /// [Obsolete("ToCachedString is deprecated. Consider using a more robust, custom implementation for text caching.")] public static class CharExtensions { private static readonly Dictionary Cache = new Dictionary(); /// /// Returns the string representation of this character which will be stored and retrieved from a dictionary cache. /// This method reduces string allocations, making it trade in processor efficiency for memory efficiency. /// /// The character to turn into a string /// A string representing the character [Obsolete("ToCachedString is deprecated. Consider using a more robust, custom implementation for text caching.")] public static string ToCachedString(this char c) { if (!CharExtensions.Cache.TryGetValue(c, out var ret)) { ret = c.ToString(); CharExtensions.Cache.Add(c, ret); } return ret; } } }