12345678910111213141516171819202122232425262728293031 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Pomelo.DotNetClient
- {
- internal class UTF8BytesCache
- {
- public static readonly UTF8BytesCache Instance = new UTF8BytesCache();
- private readonly Dictionary<string, byte[]> cache = new Dictionary<string, byte[]>();
- private UTF8BytesCache(){}
- public byte[] GetBytes(string str)
- {
- lock(cache)
- {
- byte[] ret;
- if (cache.TryGetValue(str, out ret))
- {
- return ret;
- }
- ret = Encoding.UTF8.GetBytes(str);
- cache.Add(str, ret);
- return ret;
- }
- }
- }
- }
|