remove more std::move

std::move needs to be used with pointers, we werent doing that and so a temp var was being copied onto the heap when it should of stayed on the stack. This caused memory leaks
This commit is contained in:
marauder2k7 2025-05-09 08:47:34 +01:00
parent 5fc9da789b
commit 8176145aaa
6 changed files with 12 additions and 40 deletions

View file

@ -174,34 +174,6 @@ class ConsoleValue
type = ConsoleValueType::cvNULL;
}
TORQUE_FORCEINLINE void _move(ConsoleValue&& ref) noexcept
{
if (ref.type == ConsoleValueType::cvNULL)
{
std::cout << "Cannot Move a variable twice!";
return;
}
switch (ref.type)
{
case cvInteger:
setInt(ref.i);
break;
case cvFloat:
setFloat(ref.f);
break;
case cvSTEntry:
setStringTableEntry(ref.s);
break;
case cvString:
setString(ref.s);
break;
default:
setConsoleData(ref.ct->consoleType, ref.ct->dataPtr, ref.ct->enumTable);
break;
}
ref.cleanupData();
}
public:
ConsoleValue()
{

View file

@ -89,10 +89,10 @@ public:
stack.pop_back();
}
TORQUE_FORCEINLINE void push(ConsoleValue&& val)
TORQUE_FORCEINLINE void push(ConsoleValue val)
{
Frame& frame = stack.last();
frame.values[frame.internalCounter++] = std::move(val);
frame.values[frame.internalCounter++] = (val);
}
TORQUE_FORCEINLINE void argvc(StringTableEntry fn, S32& argc, ConsoleValue** argv)

View file

@ -14,10 +14,10 @@ namespace Con
public:
EvalResult() {}
EvalResult(ConsoleValue&& pValue)
EvalResult(ConsoleValue pValue)
{
valid = true;
value = std::move(pValue);
value = (pValue);
}
EvalResult(String errorMessage)

View file

@ -16,7 +16,7 @@ namespace Con
gLastEvalResult.value.setString(pLastEvalResult.value.getString());
return pLastEvalResult;
}
inline EvalResult getLastEvalResult() { return setLastEvalResult(std::move(gLastEvalResult)); };
inline EvalResult getLastEvalResult() { return setLastEvalResult((gLastEvalResult)); };
bool runStream(Stream* byteCode, const char* fileName);

View file

@ -612,7 +612,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi
{
S32 reg = code[ip + (2 + 6 + 1 + 1) + i];
ConsoleValue& value = argv[i + 1];
Script::gEvalState.moveConsoleValue(reg, std::move(value));
Script::gEvalState.moveConsoleValue(reg, (value));
}
ip = ip + fnArgc + (2 + 6 + 1 + 1);
curFloatTable = functionFloats;
@ -1214,7 +1214,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi
case OP_RETURN:
{
returnValue = std::move(stack[_STK]);
returnValue = (stack[_STK]);
_STK--;
// Clear iterator state.
@ -1905,7 +1905,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi
if (nsEntry->mFunctionOffset)
{
ConsoleValue returnFromFn = nsEntry->mModule->exec(nsEntry->mFunctionOffset, fnName, nsEntry->mNamespace, callArgc, callArgv, false, nsEntry->mPackage).value;
stack[_STK + 1] = std::move(returnFromFn);
stack[_STK + 1] = (returnFromFn);
}
else // no body
stack[_STK + 1].setEmptyString();
@ -2040,7 +2040,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi
break;
case OP_PUSH:
gCallStack.push(std::move(stack[_STK--]));
gCallStack.push((stack[_STK--]));
break;
case OP_PUSH_FRAME:
@ -2303,7 +2303,7 @@ execFinished:
AssertFatal(!(_STK < stackStart), "String stack popped too much in script exec");
#endif
return Con::EvalResult(std::move(returnValue));
return Con::EvalResult((returnValue));
}
//------------------------------------------------------------

View file

@ -81,9 +81,9 @@ public:
currentRegisterArray->values[reg].setStringTableEntry(val);
}
TORQUE_FORCEINLINE void moveConsoleValue(S32 reg, ConsoleValue&& val)
TORQUE_FORCEINLINE void moveConsoleValue(S32 reg, ConsoleValue val)
{
currentRegisterArray->values[reg] = std::move(val);
currentRegisterArray->values[reg] = (val);
}
void pushFrame(StringTableEntry frameName, Namespace *ns, S32 regCount);