Skip to content

Commit

Permalink
Static analysis optimizations
Browse files Browse the repository at this point in the history
This changelist addresses a handful of static analysis optimizations flagged by PVS-Studio:

- Pass immutable std::string arguments by const reference.
- Remove unnecessary conversions between std::string and char*.
- Prefer std::string::empty to comparison against an empty string.
- Remove an unused local variable.
  • Loading branch information
jstone-lucasfilm committed Mar 15, 2023
1 parent 0236cbb commit 7228592
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
16 changes: 7 additions & 9 deletions source/MaterialXGraphEditor/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ void Graph::addExtraNodes()
return;
}

const std::vector<std::string> groups{ "Input Nodes", "Output Nodes", "Group Nodes", "Node Graph" };

// clear any old nodes, if we previously used tab with another graph doc
_extraNodes.clear();

Expand Down Expand Up @@ -468,7 +466,7 @@ ImVec2 Graph::layoutPosition(UiNodePtr layoutNode, ImVec2 startingPos, bool init
else
{
// don't set position of group nodes
if (node->getMessage() == "")
if (node->getMessage().empty())
{
float x = std::stof(node->getMxElement()->getAttribute("xpos"));
float y = std::stof(node->getMxElement()->getAttribute("ypos"));
Expand Down Expand Up @@ -1075,7 +1073,7 @@ void Graph::setConstant(UiNodePtr node, mx::InputPtr& input, const mx::UIPropert
}
}
// build the initial graph of a loaded mtlx document including shader, material and nodegraph node
void Graph::setUiNodeInfo(UiNodePtr node, std::string type, std::string category)
void Graph::setUiNodeInfo(UiNodePtr node, const std::string& type, const std::string& category)
{
node->setType(type);
node->setCategory(category);
Expand Down Expand Up @@ -1273,7 +1271,7 @@ void Graph::buildUiBaseGraph(mx::DocumentPtr doc)
mx::OutputPtr connectedOutput = input->getConnectedOutput();
int upNum = -1;
int downNum = -1;
if (nodeGraphName != "")
if (!nodeGraphName.empty())
{

upNum = findNode(nodeGraphName, "nodegraph");
Expand All @@ -1289,7 +1287,7 @@ void Graph::buildUiBaseGraph(mx::DocumentPtr doc)
upNum = findNode(connectedOutput->getName(), "output");
downNum = findNode(node->getName(), "node");
}
else if (input->getInterfaceName() != "")
else if (!input->getInterfaceName().empty())
{
upNum = findNode(input->getInterfaceName(), "input");
downNum = findNode(node->getName(), "node");
Expand Down Expand Up @@ -1549,7 +1547,7 @@ void Graph::buildUiNodeGraph(const mx::NodeGraphPtr& nodeGraphs)
}

// return node position in _graphNodes based off node name and type to account for input/output UiNodes with same names as mx Nodes
int Graph::findNode(std::string name, std::string type)
int Graph::findNode(const std::string& name, const std::string& type)
{
int count = 0;
for (size_t i = 0; i < _graphNodes.size(); i++)
Expand Down Expand Up @@ -1787,7 +1785,7 @@ void Graph::copyInputs()
}
}
// add node to graphNodes based off of node def information
void Graph::addNode(std::string category, std::string name, std::string type)
void Graph::addNode(const std::string& category, const std::string& name, const std::string& type)
{
mx::NodePtr node = nullptr;
std::vector<mx::NodeDefPtr> matchingNodeDefs;
Expand Down Expand Up @@ -3145,7 +3143,7 @@ void Graph::propertyEditor()
if (_currUiNode->getNode())
{
ImGui::Text("%s", _currUiNode->getNode()->getCategory().c_str());
docString += _currUiNode->getNode()->getCategory().c_str();
docString += _currUiNode->getNode()->getCategory();
docString += ":";
docString += _currUiNode->getNode()->getNodeDef()->getDocString() + "\n";
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
Expand Down
6 changes: 3 additions & 3 deletions source/MaterialXGraphEditor/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ class Graph
std::vector<int> createNodes(bool nodegraph);
int getNodeId(ed::PinId pinId);
int findNode(int nodeId);
int findNode(std::string name, std::string type);
void addNode(std::string category, std::string name, std::string type);
int findNode(const std::string& name, const std::string& type);
void addNode(const std::string& category, const std::string& name, const std::string& type);
void deleteNode(UiNodePtr node);
void setUiNodeInfo(UiNodePtr node, std::string type, std::string category);
void setUiNodeInfo(UiNodePtr node, const std::string& type, const std::string& category);

// UiEdge functions
bool edgeExists(UiEdge edge);
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGraphEditor/UiNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ UiNodePtr UiNode::getConnectedNode(const std::string& name)
}
for (UiEdge edge : edges)
{
if (edge.getInputName() == "")
if (edge.getInputName().empty())
{
return edge.getDown();
}
Expand Down

0 comments on commit 7228592

Please sign in to comment.