fix: improve performance

pull/169/head
mob-sakai 2021-06-09 01:31:39 +09:00
parent 4f9bbf57bc
commit e352d153ce
1 changed files with 14 additions and 3 deletions

View File

@ -104,7 +104,8 @@ namespace Coffee.UIParticleExtensions
internal static class MeshPool internal static class MeshPool
{ {
private static readonly Stack<Mesh> s_Pool = new Stack<Mesh>(); private static readonly Stack<Mesh> s_Pool = new Stack<Mesh>(32);
private static readonly HashSet<int> s_HashPool = new HashSet<int>();
public static void Init() public static void Init()
{ {
@ -117,6 +118,7 @@ namespace Coffee.UIParticleExtensions
var m = new Mesh(); var m = new Mesh();
m.MarkDynamic(); m.MarkDynamic();
s_Pool.Push(m); s_Pool.Push(m);
s_HashPool.Add(m.GetInstanceID());
} }
} }
@ -126,7 +128,11 @@ namespace Coffee.UIParticleExtensions
while (0 < s_Pool.Count) while (0 < s_Pool.Count)
{ {
m = s_Pool.Pop(); m = s_Pool.Pop();
if (m) return m; if (m)
{
s_HashPool.Remove(m.GetInstanceID());
return m;
}
} }
m = new Mesh(); m = new Mesh();
@ -136,9 +142,14 @@ namespace Coffee.UIParticleExtensions
public static void Return(Mesh mesh) public static void Return(Mesh mesh)
{ {
if (!mesh || s_Pool.Contains(mesh)) return; if (!mesh) return;
var id = mesh.GetInstanceID();
if (s_HashPool.Contains(id)) return;
mesh.Clear(false); mesh.Clear(false);
s_Pool.Push(mesh); s_Pool.Push(mesh);
s_HashPool.Add(id);
} }
} }