Skip to content

Commit b2c0fb1

Browse files
committed
Only copy if we're actually adding the pie slice - avoids expensive memory allocations
1 parent 5006a74 commit b2c0fb1

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

Activities/GAScripted.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ void GAScripted::AddPieSlicesToActiveActorPieMenus() {
559559
PieMenu *controlledActorPieMenu = m_ControlledActor[player]->GetPieMenu();
560560
if (controlledActorPieMenu && m_ControlledActor[player]->GetController()->IsState(PIE_MENU_ACTIVE) && controlledActorPieMenu->IsEnabling()) {
561561
for (const std::unique_ptr<PieSlice> &pieSlice : m_PieSlicesToAdd) {
562-
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(dynamic_cast<PieSlice *>(pieSlice->Clone()), this, true);
562+
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(pieSlice.get(), this, true);
563563
}
564564
for (const GlobalScript *globalScript : m_GlobalScriptsList) {
565565
if (globalScript->IsActive()) {
566566
for (const std::unique_ptr<PieSlice> &pieSlice : globalScript->GetPieSlicesToAdd()) {
567-
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(dynamic_cast<PieSlice *>(pieSlice->Clone()), globalScript, true);
567+
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(pieSlice.get(), globalScript, true);
568568
}
569569
}
570570
}

Entities/PieMenu.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ namespace RTE {
378378
const std::string &pieSlicePresetName = pieSliceToAdd->GetPresetName();
379379

380380
if (pieSlicePresetName == "None") {
381-
return AddPieSlice(pieSliceToAdd, pieSliceOriginalSource, allowQuadrantOverflow);
381+
return AddPieSlice(dynamic_cast<PieSlice*>(pieSliceToAdd->Clone()), pieSliceOriginalSource, allowQuadrantOverflow);
382382
}
383383

384384
bool pieSliceAlreadyExists = onlyCheckPieSlicesWithSameOriginalSource ? false : GetFirstPieSliceByPresetName(pieSlicePresetName) != nullptr;
@@ -392,11 +392,10 @@ namespace RTE {
392392
}
393393

394394
if (pieSliceAlreadyExists) {
395-
delete pieSliceToAdd;
396395
return false;
397396
}
398397

399-
return AddPieSlice(pieSliceToAdd, pieSliceOriginalSource, allowQuadrantOverflow);
398+
return AddPieSlice(dynamic_cast<PieSlice*>(pieSliceToAdd->Clone()), pieSliceOriginalSource, allowQuadrantOverflow);
400399
}
401400

402401
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Lua/LuaBindingsEntities.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,9 +1210,9 @@ namespace RTE {
12101210
.def("GetFirstPieSliceByType", &PieMenu::GetFirstPieSliceByType)
12111211
.def("AddPieSlice", &PieMenu::AddPieSlice, luabind::adopt(_2))
12121212
.def("AddPieSlice", &LuaAdaptersPieMenu::AddPieSlice, luabind::adopt(_2))
1213-
.def("AddPieSliceIfPresetNameIsUnique", &PieMenu::AddPieSliceIfPresetNameIsUnique, luabind::adopt(_2))
1214-
.def("AddPieSliceIfPresetNameIsUnique", &LuaAdaptersPieMenu::AddPieSliceIfPresetNameIsUnique1, luabind::adopt(_2))
1215-
.def("AddPieSliceIfPresetNameIsUnique", &LuaAdaptersPieMenu::AddPieSliceIfPresetNameIsUnique2, luabind::adopt(_2))
1213+
.def("AddPieSliceIfPresetNameIsUnique", &PieMenu::AddPieSliceIfPresetNameIsUnique)
1214+
.def("AddPieSliceIfPresetNameIsUnique", &LuaAdaptersPieMenu::AddPieSliceIfPresetNameIsUnique1)
1215+
.def("AddPieSliceIfPresetNameIsUnique", &LuaAdaptersPieMenu::AddPieSliceIfPresetNameIsUnique2)
12161216
.def("RemovePieSlice", &PieMenu::RemovePieSlice, luabind::adopt(luabind::return_value))
12171217
.def("RemovePieSlicesByPresetName", &PieMenu::RemovePieSlicesByPresetName)
12181218
.def("RemovePieSlicesByType", &PieMenu::RemovePieSlicesByType)

0 commit comments

Comments
 (0)