Browse Source

Optimize: Reduce unnecessary coping

Akeit0 11 months ago
parent
commit
975a5b89fb
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/Lua/LuaCoroutine.cs

+ 4 - 3
src/Lua/LuaCoroutine.cs

@@ -60,9 +60,10 @@ public sealed class LuaCoroutine : LuaThread, IValueTaskSource<LuaCoroutine.Yiel
                     if (isFirstCall)
                     {
                         // copy stack value
-                        Stack.EnsureCapacity(baseThread.Stack.Count);
-                        baseThread.Stack.AsSpan().CopyTo(Stack.GetBuffer());
-                        Stack.NotifyTop(baseThread.Stack.Count);
+                        var argCount = context.ArgumentCount;
+                        Stack.EnsureCapacity(argCount);
+                        baseThread.Stack.AsSpan()[^argCount..].CopyTo(Stack.GetBuffer());
+                        Stack.NotifyTop(argCount);
                     }
                     else
                     {