Skip to content

Commit 5f1f740

Browse files
author
ElPsyCongree
committed
把list改成stack
1 parent 423a42c commit 5f1f740

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

LuaProfiler/LuaProfilerClient/Core/Driver/LuaProfiler.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class LuaProfiler
1919
{
2020
#region member
2121
private static IntPtr _mainL = IntPtr.Zero;
22-
private static readonly List<Sample> beginSampleMemoryStack = new List<Sample>();
22+
private static readonly Stack<Sample> beginSampleMemoryStack = new Stack<Sample>();
2323
private static int m_currentFrame = 0;
2424
private static Dictionary<MethodBase, string> m_methodNameDict = new Dictionary<MethodBase, string>(4096);
2525
public static int mainThreadId = -100;
@@ -166,13 +166,13 @@ public static void BeginSample(IntPtr luaState, string name)
166166
}
167167
long memoryCount = LuaLib.GetLuaMemory(luaState);
168168
Sample sample = Sample.Create(getcurrentTime, (int)memoryCount, name);
169-
beginSampleMemoryStack.Add(sample);
169+
beginSampleMemoryStack.Push(sample);
170170
}
171171
public static void PopAllSampleWhenLateUpdate()
172172
{
173-
for (int i = 0, imax = beginSampleMemoryStack.Count; i < imax; i++)
173+
while(beginSampleMemoryStack.Count > 0)
174174
{
175-
var item = beginSampleMemoryStack[i];
175+
var item = beginSampleMemoryStack.Pop();
176176
if (item.fahter == null)
177177
{
178178
NetWorkClient.SendMessage(item);
@@ -197,8 +197,7 @@ public static void EndSample(IntPtr luaState)
197197
}
198198
long nowMemoryCount = LuaLib.GetLuaMemory(luaState);
199199
long nowMonoCount = GC.GetTotalMemory(false);
200-
Sample sample = beginSampleMemoryStack[beginSampleMemoryStack.Count - 1];
201-
beginSampleMemoryStack.RemoveAt(beginSampleMemoryStack.Count - 1);
200+
Sample sample = beginSampleMemoryStack.Pop();
202201

203202
sample.costTime = (int)(getcurrentTime - sample.currentTime);
204203
var monoGC = nowMonoCount - sample.currentMonoMemory;
@@ -211,7 +210,7 @@ public static void EndSample(IntPtr luaState)
211210
sample.Restore();
212211
return;
213212
}
214-
sample.fahter = beginSampleMemoryStack.Count > 0 ? beginSampleMemoryStack[beginSampleMemoryStack.Count - 1] : null;
213+
sample.fahter = beginSampleMemoryStack.Count > 0 ? beginSampleMemoryStack.Peek() : null;
215214
//UnityEngine.Debug.Log(sample.name);
216215
if (beginSampleMemoryStack.Count == 0)
217216
{

0 commit comments

Comments
 (0)