Merged in liortal/unity-ui-extensions/liortal/improve-memory-behaviour-by-preallocatin-1444835033293 (pull request #12)

Improve memory behaviour by pre-allocating the right amount of memory.

--HG--
branch : develop_5.2
pull/413/head
Simon Jackson 2015-10-15 12:17:03 +01:00
commit 78537fc15d
1 changed files with 8 additions and 10 deletions

View File

@ -8,6 +8,8 @@ namespace UnityEngine.UI.Extensions
[AddComponentMenu("UI/Effects/Extensions/Nicer Outline")]
public class NicerOutline : BaseMeshEffect
{
private const int VERTICES_PER_QUAD = 6;
[SerializeField]
private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f);
@ -91,10 +93,6 @@ namespace UnityEngine.UI.Extensions
{
UIVertex vt;
var neededCpacity = verts.Count * 2;
if (verts.Capacity < neededCpacity)
verts.Capacity = neededCpacity;
for (int i = start; i < end; ++i)
{
vt = verts[i];
@ -114,10 +112,6 @@ namespace UnityEngine.UI.Extensions
protected void ApplyShadow(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
{
var neededCpacity = verts.Count * 2;
if (verts.Capacity < neededCpacity)
verts.Capacity = neededCpacity;
ApplyShadowZeroAlloc(verts, color, start, end, x, y);
}
@ -128,8 +122,12 @@ namespace UnityEngine.UI.Extensions
{
return;
}
List < UIVertex > verts = new List<UIVertex>();
using (var helper = new VertexHelper(mesh))
// Initilize a list with the correct capacity, to avoid unneeded allocations later.
// The list will hold 9 copies of the vertex data (original + 8 copies).
List < UIVertex > verts = new List<UIVertex>(9 * (mesh.vertices.Length / 4 * VERTICES_PER_QUAD));
using (var helper = new VertexHelper(mesh))
{
helper.GetUIVertexStream(verts);
}