Skip to content

Commit

Permalink
pcp: hold map expression variables by unique_ptr
Browse files Browse the repository at this point in the history
PcpMapExpression::Variables are only ever held by PcpLayerStack so we
don't need shared_ptr here.

(Internal change: 2048963)
  • Loading branch information
jloy authored and pixar-oss committed Mar 12, 2020
1 parent ea8c17f commit 7e21bd3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pxr/usd/pcp/layerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,13 @@ PcpLayerStack::GetExpressionForRelocatesAtPath(const SdfPath &path)
}

// Create a Variable representing the relocations that affect this path.
PcpMapExpression::VariableRefPtr var =
PcpMapExpression::VariableUniquePtr var =
PcpMapExpression::NewVariable(_FilterRelocationsForPath(*this, path));

// Retain the variable so that we can update it if relocations change.
_relocatesVariables[path] = var;
i = _relocatesVariables.emplace(path, std::move(var)).first;

return var->GetExpression();
return i->second->GetExpression();
}

void
Expand Down
2 changes: 1 addition & 1 deletion pxr/usd/pcp/layerStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class PcpLayerStack : public TfRefBase, public TfWeakBase, boost::noncopyable {
/// the current value of relocations given out by
/// GetExpressionForRelocatesAtPath(). This map is used to update
/// those values when relocations change.
typedef std::map<SdfPath, PcpMapExpression::VariableRefPtr,
typedef std::map<SdfPath, PcpMapExpression::VariableUniquePtr,
SdfPath::FastLessThan> _RelocatesVarMap;
_RelocatesVarMap _relocatesVariables;

Expand Down
14 changes: 7 additions & 7 deletions pxr/usd/pcp/mapExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,35 @@ PcpMapExpression::Variable::~Variable()
}

// Private implementation for Variable.
struct Pcp_VariableImpl : PcpMapExpression::Variable
struct Pcp_VariableImpl final : PcpMapExpression::Variable
{
virtual ~Pcp_VariableImpl() {}
~Pcp_VariableImpl() override {}

Pcp_VariableImpl(const PcpMapExpression::_NodeRefPtr &node) : _node(node) {}

virtual const PcpMapExpression::Value & GetValue() const {
const PcpMapExpression::Value & GetValue() const override {
return _node->GetValueForVariable();
}

virtual void SetValue(const PcpMapExpression::Value & value) {
void SetValue(const PcpMapExpression::Value & value) override {
_node->SetValueForVariable(value);
}

virtual PcpMapExpression GetExpression() const {
PcpMapExpression GetExpression() const override {
return PcpMapExpression(_node);
}

const PcpMapExpression::_NodeRefPtr _node;
};

PcpMapExpression::VariableRefPtr
PcpMapExpression::VariableUniquePtr
PcpMapExpression::NewVariable( const Value & initialValue )
{
Pcp_VariableImpl *var = new Pcp_VariableImpl( _Node::New(_OpVariable) );

var->SetValue(initialValue);

return VariableRefPtr(var);
return VariableUniquePtr(var);
}

////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions pxr/usd/pcp/mapExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PcpMapExpression
};

/// Variables are held by reference.
typedef std::shared_ptr<Variable> VariableRefPtr;
typedef std::unique_ptr<Variable> VariableUniquePtr;

/// Create a new variable.
/// The client is expected to retain the reference for as long as
Expand All @@ -118,7 +118,7 @@ class PcpMapExpression
/// will continue to be valid, but there will be no way to further
/// change the value of the variable.
PCP_API
static VariableRefPtr NewVariable( const Value & initialValue );
static VariableUniquePtr NewVariable( const Value & initialValue );

/// Create a new PcpMapExpression representing the application of
/// f's value, followed by the application of this expression's value.
Expand Down
2 changes: 1 addition & 1 deletion pxr/usd/pcp/testenv/testPcpMapExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ main(int argc, char** argv)
// Variable
{
// Variable will initial empty function
PcpMapExpression::VariableRefPtr var =
PcpMapExpression::VariableUniquePtr var =
PcpMapExpression::NewVariable( PcpMapFunction() );
const PcpMapExpression varExpr = var->GetExpression();
testExprs.push_back(varExpr);
Expand Down

0 comments on commit 7e21bd3

Please sign in to comment.