Skip to content

Commit ac731d8

Browse files
committed
Optimize: Use more Span.Copy for coroutine.resume
1 parent 4aa9e40 commit ac731d8

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/Lua/LuaCoroutine.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,19 @@ public override async ValueTask<int> ResumeAsync(LuaFunctionExecutionContext con
123123
if (variableArgumentCount > 0)
124124
{
125125
var fixedArgumentCount = context.ArgumentCount - 1 - variableArgumentCount;
126+
var args = context.Arguments;
126127

127-
for (int i = 0; i < variableArgumentCount; i++)
128-
{
129-
Stack.Push(context.GetArgument(i + fixedArgumentCount + 1));
130-
}
128+
Stack.PushRange(args.Slice(1 + fixedArgumentCount, variableArgumentCount));
131129

132130
frameBase = Stack.Count;
133131

134-
for (int i = 0; i < fixedArgumentCount; i++)
135-
{
136-
Stack.Push(context.GetArgument(i + 1));
137-
}
132+
Stack.PushRange(args.Slice(1, fixedArgumentCount));
138133
}
139134
else
140135
{
141136
frameBase = Stack.Count;
142137

143-
for (int i = 0; i < context.ArgumentCount - 1; i++)
144-
{
145-
Stack.Push(context.GetArgument(i + 1));
146-
}
138+
Stack.PushRange(context.Arguments[1..]);
147139
}
148140

149141
functionTask = Function.InvokeAsync(new()

0 commit comments

Comments
 (0)