Skip to content

Commit 9f7adc3

Browse files
Static analysis optimizations (#2349)
This changelist addresses a handful of recommendations from PVS-Studio, replacing `std::vector::push_back` with `std::vector::emplace_back` to minimize string copies.
1 parent c5ade72 commit 9f7adc3

6 files changed

Lines changed: 10 additions & 7 deletions

File tree

source/MaterialXGenMdl/Nodes/HeightToNormalNodeMdl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void HeightToNormalNodeMdl::computeSampleOffsetStrings(const string& sampleSizeN
4242
{
4343
for (int col = -1; col <= 1; col++)
4444
{
45-
offsetStrings.push_back(" + " + sampleSizeName + " * " + offsetTypeString + "(" + std::to_string(float(col)) + "," + std::to_string(float(row)) + ")");
45+
offsetStrings.emplace_back(" + " + sampleSizeName + " * " + offsetTypeString +
46+
"(" + std::to_string(float(col)) + "," + std::to_string(float(row)) + ")");
4647
}
4748
}
4849
}

source/MaterialXGenOsl/OslShaderGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,15 @@ void OslShaderGenerator::emitMetadata(const ShaderPort* port, ShaderStage& stage
493493
const string& delim = (widgetMetadata || j < metadata->size() - 1) ? Syntax::COMMA : EMPTY_STRING;
494494
const string& dataType = _syntax->getTypeName(data.type);
495495
const string dataValue = _syntax->getValue(data.type, *data.value, true);
496-
metadataLines.push_back(dataType + " " + data.name + " = " + dataValue + delim);
496+
metadataLines.emplace_back(dataType + " " + data.name + " = " + dataValue + delim);
497497
}
498498
}
499499
}
500500
if (widgetMetadata)
501501
{
502502
const string& dataType = _syntax->getTypeName(widgetMetadata->type);
503503
const string dataValue = _syntax->getValue(widgetMetadata->type, *widgetMetadata->value, true);
504-
metadataLines.push_back(dataType + " " + widgetMetadata->name + " = " + dataValue);
504+
metadataLines.emplace_back(dataType + " " + widgetMetadata->name + " = " + dataValue);
505505
}
506506
if (metadataLines.size())
507507
{

source/MaterialXGenShader/Nodes/BlurNode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void BlurNode::computeSampleOffsetStrings(const string& sampleSizeName, const st
4141
{
4242
for (int col = -w; col <= w; col++)
4343
{
44-
offsetStrings.push_back(" + " + sampleSizeName + " * " + offsetTypeString + "(" + std::to_string(float(col)) + "," + std::to_string(float(row)) + ")");
44+
offsetStrings.emplace_back(" + " + sampleSizeName + " * " + offsetTypeString +
45+
"(" + std::to_string(float(col)) + "," + std::to_string(float(row)) + ")");
4546
}
4647
}
4748
}

source/MaterialXGenShader/Nodes/ConvolutionNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void ConvolutionNode::emitInputSamplesUV(const ShaderNode& node,
186186
context.removeOutputSuffix(upstreamOutput);
187187

188188
// Keep track of the output name with the suffix
189-
sampleStrings.push_back(upstreamOutput->getVariable() + outputSuffix);
189+
sampleStrings.emplace_back(upstreamOutput->getVariable() + outputSuffix);
190190
}
191191
}
192192
else

source/MaterialXGenShader/Nodes/HwHeightToNormalNode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void HwHeightToNormalNode::computeSampleOffsetStrings(const string& sampleSizeNa
4646
{
4747
for (int col = -1; col <= 1; col++)
4848
{
49-
offsetStrings.push_back(" + " + sampleSizeName + " * " + offsetTypeString + "(" + std::to_string(float(col)) + "," + std::to_string(float(row)) + ")");
49+
offsetStrings.emplace_back(" + " + sampleSizeName + " * " + offsetTypeString +
50+
"(" + std::to_string(float(col)) + "," + std::to_string(float(row)) + ")");
5051
}
5152
}
5253
}

source/MaterialXGraphEditor/Graph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Graph::Graph(const std::string& materialFilename,
176176
_renderer->initialize();
177177
for (const std::string& ext : _renderer->getImageHandler()->supportedExtensions())
178178
{
179-
_imageFilter.push_back("." + ext);
179+
_imageFilter.emplace_back("." + ext);
180180
}
181181
_renderer->updateMaterials(nullptr);
182182
for (const std::string& incl : _renderer->getXincludeFiles())

0 commit comments

Comments
 (0)