Skip to content

Commit 45c90b9

Browse files
authored
(bugfix): Prevent unnecessary copies with more std::move and emplace (#1870)
* Prevent unnecessary copies of tmp handles in metadata manager * Add some more missing emplace * One last emplace * Optimize HM3D semantic scene a bit * Fix some more missing std::move * Add another missing emplace
1 parent 83fe46b commit 45c90b9

9 files changed

Lines changed: 16 additions & 16 deletions

src/esp/core/Configuration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ class Configuration {
748748
*/
749749
std::shared_ptr<Configuration> addSubgroup(const std::string& name) {
750750
// Attempt to insert an empty pointer
751-
auto result = configMap_.insert({name, std::shared_ptr<Configuration>{}});
751+
auto result = configMap_.emplace(name, std::shared_ptr<Configuration>{});
752752
// If name not already present (insert succeeded) then add new
753753
// configuration
754754
if (result.second) {

src/esp/geo/VoxelGrid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ void VoxelGrid::generateMeshDataAndMeshGL(
288288
if (meshGLDict_.find(gridName) != meshGLDict_.end()) {
289289
meshGLDict_[gridName] = Mn::MeshTools::compile(*meshDataDict_[gridName]);
290290
} else {
291-
meshGLDict_.insert(std::make_pair(
292-
gridName, Mn::MeshTools::compile(*meshDataDict_[gridName])));
291+
meshGLDict_.emplace(gridName,
292+
Mn::MeshTools::compile(*meshDataDict_[gridName]));
293293
}
294294
}
295295

src/esp/geo/VoxelGrid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class VoxelGrid {
130130

131131
new_grid.view = view;
132132
new_grid.type = type;
133-
grids_.insert(std::make_pair(gridName, std::move(new_grid)));
133+
grids_.emplace(gridName, std::move(new_grid));
134134
}
135135

136136
/**

src/esp/metadata/managers/AssetAttributesManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ AssetAttributesManager::AssetAttributesManager()
104104
auto tmplt = AssetAttributesManager::createObject(elem.second, true);
105105
std::string tmpltHandle = tmplt->getHandle();
106106
defaultPrimAttributeHandles_[elem.second] = tmpltHandle;
107-
this->undeletableObjectNames_.insert(tmpltHandle);
107+
this->undeletableObjectNames_.insert(std::move(tmpltHandle));
108108
}
109109

110110
ESP_DEBUG() << "Built default primitive asset templates :"

src/esp/metadata/managers/AttributesManagerBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ std::vector<int> AttributesManager<T, Access>::loadAllFileBasedTemplates(
277277
// save handles in list of defaults, so they are not removed, if desired.
278278
if (saveAsDefaults) {
279279
std::string tmpltHandle = tmplt->getHandle();
280-
this->undeletableObjectNames_.insert(tmpltHandle);
280+
this->undeletableObjectNames_.insert(std::move(tmpltHandle));
281281
}
282282
templateIndices[i] = tmplt->getID();
283283
}

src/esp/metadata/managers/ObjectAttributesManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void ObjectAttributesManager::createDefaultPrimBasedAttributesTemplates() {
6666
auto tmplt = createPrimBasedAttributesTemplate(elem, true);
6767
// save handles in list of defaults, so they are not removed
6868
std::string tmpltHandle = tmplt->getHandle();
69-
this->undeletableObjectNames_.insert(tmpltHandle);
69+
this->undeletableObjectNames_.insert(std::move(tmpltHandle));
7070
}
7171
} // ObjectAttributesManager::createDefaultPrimBasedAttributesTemplates
7272

src/esp/metadata/managers/StageAttributesManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ StageAttributesManager::StageAttributesManager(
4141
auto tmplt = this->postCreateRegister(
4242
StageAttributesManager::initNewObjectInternal("NONE", false), true);
4343
std::string tmpltHandle = tmplt->getHandle();
44-
this->undeletableObjectNames_.insert(tmpltHandle);
44+
this->undeletableObjectNames_.insert(std::move(tmpltHandle));
4545
} // StageAttributesManager::ctor
4646

4747
int StageAttributesManager::registerObjectFinalize(

src/esp/scene/HM3DSemanticScene.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ void buildInstanceRegionCategory(
7676
instanceID, 0, objCategoryName,
7777
Cr::Utility::formatString("{}_{}", objCategoryName, instanceID),
7878
colorInt};
79-
objInstance[instanceID] = obj;
79+
objInstance[instanceID] = std::move(obj);
8080
// find category, build if dne
8181
TempHM3DCategory tmpCat{
8282
static_cast<int>(categories.size()), objCategoryName, {}};
83-
auto categoryIter = categories.emplace(objCategoryName, tmpCat);
83+
auto categoryIter = categories.emplace(objCategoryName, std::move(tmpCat));
8484
categoryIter.first->second.objInstances.push_back(&objInstance[instanceID]);
8585
// find region, build if dne
8686
TempHM3DRegion tmpRegion{regionID, {}};
87-
auto regionIter = regions.emplace(regionID, tmpRegion);
87+
auto regionIter = regions.emplace(regionID, std::move(tmpRegion));
8888
regionIter.first->second.objInstances.push_back(&objInstance[instanceID]);
8989
} // buildInstanceRegionCategory
9090

@@ -133,7 +133,7 @@ bool SemanticScene::buildHM3DHouse(std::ifstream& ifs,
133133
uint8_t((colorInt >> 8) & 0xff),
134134
uint8_t(colorInt & 0xff)};
135135
// object category will possibly have commas
136-
const std::string objCategoryName = tokens[1];
136+
const std::string& objCategoryName = tokens[1];
137137
// room/region is always last token - get rid of first comma
138138
int regionID =
139139
std::stoi(Cr::Utility::String::trim(tokens[tokens.size() - 1], " ,"));
@@ -173,7 +173,7 @@ bool SemanticScene::buildHM3DHouse(std::ifstream& ifs,
173173
for (TempHM3DObject* objItem : regionItem.second.objInstances) {
174174
objItem->region = regionPtr;
175175
}
176-
scene.regions_.emplace_back(regionPtr);
176+
scene.regions_.emplace_back(std::move(regionPtr));
177177
}
178178

179179
// build all object instances
@@ -188,8 +188,8 @@ bool SemanticScene::buildHM3DHouse(std::ifstream& ifs,
188188
// set region
189189
objPtr->parentIndex_ = obj.region->index_;
190190
objPtr->region_ = obj.region;
191-
objPtr->region_->objects_.push_back(objPtr);
192-
scene.objects_.emplace_back(objPtr);
191+
objPtr->region_->objects_.emplace_back(objPtr);
192+
scene.objects_.emplace_back(std::move(objPtr));
193193
}
194194
scene.hasVertColors_ = true;
195195

src/esp/scene/SemanticScene.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ SemanticScene::buildCCBasedSemanticObjs(
182182
std::unordered_map<uint32_t, uint32_t> mapColorIntsToSemanticObjIDXs;
183183
mapColorIntsToSemanticObjIDXs.reserve(semanticObjs.size());
184184
for (uint32_t i = 0; i < semanticObjs.size(); ++i) {
185-
mapColorIntsToSemanticObjIDXs.insert({semanticObjs[i]->getColorAsInt(), i});
185+
mapColorIntsToSemanticObjIDXs.emplace(semanticObjs[i]->getColorAsInt(), i);
186186
}
187187
// build map with key being semanticObject IDX in semantic Objects array
188188
std::unordered_map<uint32_t, std::vector<scene::CCSemanticObject::ptr>>

0 commit comments

Comments
 (0)