Repository navigation
оптимизация передачи параметров при вызовах методов #1790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
c5cf643
b95fd3b
a52d4f6
d6205ac
1169044
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -904,7 +904,8 @@ | |
|
|
||
| for (--argCount; argCount >= 0; --argCount) | ||
| { | ||
| args[argCount] = _operationStack.Pop(); | ||
| var arg = _operationStack.Pop(); | ||
| args[argCount] = arg.IsSkippedArgument() ? null : arg; | ||
|
Comment on lines
+907
to
+908
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis
Restore skipped arguments only in the compiled-block adapter. Do not reverse Dynamic calls pass the array unchanged to Suggested fix
🤖 Prompt for AI Agents
|
||
| } | ||
| return args; | ||
| } | ||
|
|
@@ -961,26 +962,18 @@ | |
|
|
||
| private void CallContext(IRuntimeContextInstance instance, int index, BslMethodInfo methodInfo, IValue[] argValues, bool asFunc) | ||
| { | ||
| IValue[] realArgs; | ||
| if (instance.DynamicMethodSignatures) | ||
| { | ||
| realArgs = argValues; | ||
| } | ||
| else | ||
| { | ||
| realArgs = new IValue[methodInfo.CallParameters.Length]; | ||
| var skippedArg = BslSkippedParameterValue.Instance; | ||
| int i = 0; | ||
| for (; i < argValues.Length; i++) | ||
| { | ||
| realArgs[i] = argValues[i]; | ||
| } | ||
| for (; i < realArgs.Length; i++) | ||
| { | ||
| realArgs[i] = skippedArg; | ||
| } | ||
| } | ||
|
|
||
| IValue[] realArgs = argValues; | ||
| if (!instance.DynamicMethodSignatures) | ||
| { | ||
| int parCount = methodInfo.CallParameters.Length; | ||
| int argCount = argValues.Length; | ||
| if (argCount < parCount) | ||
| { | ||
| Array.Resize(ref realArgs, parCount); | ||
| // для неуказанных параметров останется null | ||
| } | ||
| } | ||
|
|
||
| if (asFunc) | ||
| { | ||
| instance.CallAsFunction(index, realArgs, out IValue retVal, _process); | ||
|
|
@@ -1040,59 +1033,56 @@ | |
| NextInstruction(); | ||
| } | ||
|
|
||
| private void PrepareContextCallArguments(int arg, out IRuntimeContextInstance context, out int methodId, out IValue[] argValues) | ||
| { | ||
| var factArgs = PopArguments(); | ||
| var argCount = factArgs.Length; | ||
|
|
||
| var argCount = factArgs.Length; | ||
| argValues = factArgs; | ||
|
|
||
| var objIValue = _operationStack.Pop(); | ||
| context = objIValue.AsObject(); | ||
| var methodName = _module.Identifiers[arg]; | ||
| methodId = context.GetMethodNumber(methodName); | ||
| methodId = context.GetMethodNumber(methodName); | ||
| if (context.DynamicMethodSignatures) | ||
| { | ||
| argValues = new IValue[argCount]; | ||
| for (int i = 0; i < argCount; i++) | ||
| { | ||
| var argValue = factArgs[i]; | ||
| if (!argValue.IsSkippedArgument()) | ||
| { | ||
| argValues[i] = argValue; | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| var methodInfo = context.GetMethodInfo(methodId); | ||
| var methodParams = methodInfo.CallParameters; | ||
|
|
||
| if (argCount > methodParams.Length) | ||
| throw RuntimeException.TooManyArgumentsPassed(); | ||
|
|
||
| argValues = new IValue[methodParams.Length]; | ||
| int i = 0; | ||
| for (; i < argCount; i++) | ||
| { | ||
| var argValue = factArgs[i]; | ||
| if (!argValue.IsSkippedArgument()) | ||
| { | ||
| if (methodParams[i].IsByRef) | ||
| { | ||
| argValues[i] = argValue is IVariable? argValue : Variable.Create(argValue, ""); | ||
| } | ||
| else | ||
| argValues[i] = RawValue(argValue); | ||
| } | ||
| else if(!methodParams[i].HasDefaultValue) | ||
| throw RuntimeException.MissedArgument(); | ||
| } | ||
| for (; i < methodParams.Length; i++) | ||
| { | ||
| if (!methodParams[i].HasDefaultValue) | ||
| throw RuntimeException.TooFewArgumentsPassed(); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| var methodInfo = context.GetMethodInfo(methodId); | ||
| var methodParams = methodInfo.CallParameters; | ||
| int parCount = methodParams.Length; | ||
|
|
||
| if (argCount > parCount) | ||
| throw RuntimeException.TooManyArgumentsPassed(); | ||
|
|
||
| if (argCount < parCount) | ||
| { | ||
| Array.Resize(ref argValues, parCount); | ||
| while (--parCount >= argCount) | ||
| { | ||
| if (!methodParams[parCount].HasDefaultValue) | ||
| throw RuntimeException.TooFewArgumentsPassed(); | ||
| // иначе останется null как неуказанный параметр | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < argCount; i++) | ||
| { | ||
| var argValue = factArgs[i]; | ||
| if (argValue is IValueReference r) | ||
| { | ||
| if (!methodParams[i].IsByRef) | ||
| argValues[i] = r.Value; | ||
| } | ||
| else if (argValue is not null) | ||
| { | ||
| if (methodParams[i].IsByRef) | ||
| argValues[i] = Variable.Create(argValue, ""); | ||
| } | ||
| else if (!methodParams[i].HasDefaultValue) | ||
| throw RuntimeException.MissedArgument(); | ||
| } | ||
| } | ||
|
|
||
| private void Jmp(int arg) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: EvilBeaver/OneScript
Length of output: 36232
🏁 Script executed:
Repository: EvilBeaver/OneScript
Length of output: 37405
🏁 Script executed:
Repository: EvilBeaver/OneScript
Length of output: 44031
🏁 Script executed:
Repository: EvilBeaver/OneScript
Length of output: 42074
Restore write-back for dynamic callbacks.
ReflectorContext.CallMethodpasses a copiedIValue[]to dynamic targets and no longer copies changes back toarguments. ADelegateActioncallback can assign an output value in that array, but the caller'sArrayImplthen keeps the old value.Restore copy-back for dynamic calls, including when the target throws.
🐛 Suggested fix
🤖 Prompt for AI Agents