Skip to content

Commit 43a0a07

Browse files
committed
Don't use double the memory for async SWF assembly
1 parent dee2abf commit 43a0a07

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

Native/BytecodeEditor/source/BytecodeEditor.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,7 @@ FREObject BytecodeEditor::assembleAsync(
142142
ABC::ABCWriter(Assembler::assemble(strings, includeDebugInstructions).toABC())
143143
.data());
144144

145-
currentSWF->replaceABCData(data.data(), data.size());
146-
147-
std::vector<uint8_t> finalData(currentSWF->getFullSize());
148-
149-
currentSWF->writeTo(finalData.data());
150-
151-
SUCCEED_ASYNC(finalData);
145+
SUCCEED_ASYNC(data);
152146
}
153147
catch (std::exception& e)
154148
{
@@ -269,15 +263,9 @@ FREObject BytecodeEditor::finishAssembleAsync()
269263
std::vector<uint8_t> data =
270264
std::move(ABC::ABCWriter(partialAssembly->toABC()).data());
271265

272-
currentSWF->replaceABCData(data.data(), data.size());
273-
274-
std::vector<uint8_t> finalData(currentSWF->getFullSize());
275-
276-
currentSWF->writeTo(finalData.data());
277-
278266
partialAssembly = nullptr;
279267

280-
SUCCEED_ASYNC(finalData);
268+
SUCCEED_ASYNC(data);
281269
}
282270
catch (std::exception& e)
283271
{
@@ -352,9 +340,17 @@ FREObject BytecodeEditor::taskResult()
352340
{
353341
const auto& data = std::get<3>(m_taskResult);
354342

343+
if (!currentSWF)
344+
{
345+
FAIL("Current SWF not set when trying to access result data. Did you accidentally "
346+
"clean up first?");
347+
}
348+
349+
currentSWF->replaceABCData(data.data(), data.size());
350+
355351
FREObject lengthObj;
356-
DO_OR_FAIL(
357-
"Failed to create length object", FRENewObjectFromUint32(data.size(), &lengthObj));
352+
DO_OR_FAIL("Failed to create length object",
353+
FRENewObjectFromUint32(currentSWF->getFullSize(), &lengthObj));
358354

359355
FREObject bytearrayObj;
360356
DO_OR_FAIL("Failed to create returned bytearray",
@@ -366,7 +362,8 @@ FREObject BytecodeEditor::taskResult()
366362
FREByteArray ba;
367363
DO_OR_FAIL("Failed to acquire bytearray", FREAcquireByteArray(bytearrayObj, &ba));
368364

369-
std::copy(data.begin(), data.end(), ba.bytes);
365+
currentSWF->writeTo(ba.bytes);
366+
370367
DO_OR_FAIL("Failed to release bytearray", FREReleaseByteArray(bytearrayObj));
371368

372369
m_taskResult = std::monostate{};

0 commit comments

Comments
 (0)