From ea94c070110e8de2cb55fed633b51b9f9cf3594d Mon Sep 17 00:00:00 2001 From: howsohazard <143410553+howsohazard@users.noreply.github.com> Date: Wed, 29 May 2024 14:26:04 -0400 Subject: [PATCH] 20412: Reduces memory allocations for assign and accum opcodes (#141) --- src/Amalgam/interpreter/InterpreterOpcodesBase.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp b/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp index bd1beeec..2c9c572b 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp @@ -1006,9 +1006,12 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_ASSIGN_and_ACCUM(Evaluable if(value_destination == nullptr) value_destination = GetOrCreateCallStackSymbolLocation(variable_sid, destination_call_stack_index); - //need to make a copy so that modifications can be dropped in directly - // this is essential as some values may be shared by other areas of memory, threads, or entities - EvaluableNode *value_replacement = evaluableNodeManager->DeepAllocCopy(*value_destination); + EvaluableNode *value_replacement = *value_destination; + #ifdef MULTITHREAD_SUPPORT + //if editing a shared variable, then need to make a copy before editing in place to prevent another thread from reading the data structure mid-edit + if(accum && destination_call_stack_index < callStackUniqueAccessStartingDepth) + value_replacement = evaluableNodeManager->DeepAllocCopy(value_replacement); + #endif for(size_t index = 0; index < num_replacements; index++) {