Skip to content

Commit

Permalink
Removed unnecessary InternedString construction from Expression node.
Browse files Browse the repository at this point in the history
This knocks 6% off the runtime when traversing a cached scene generated by 100 CustomAttributes nodes each with expressions.
  • Loading branch information
johnhaddon committed Oct 14, 2014
1 parent ff82490 commit 1b96bb8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
6 changes: 6 additions & 0 deletions include/Gaffer/Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class Expression : public ComputeNode

private :

CompoundPlug *inPlug();
const CompoundPlug *inPlug() const;

ValuePlug *outPlug();
const ValuePlug *outPlug() const;

void plugSet( Plug *plug );
void parentChanged( GraphComponent *child, GraphComponent *oldParent );

Expand Down
47 changes: 35 additions & 12 deletions src/Gaffer/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@

using namespace Gaffer;

static IECore::InternedString g_inPlugName( "in" );
static IECore::InternedString g_outPlugName( "out" );

//////////////////////////////////////////////////////////////////////////
// Expression implementation
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -106,8 +109,8 @@ void Expression::affects( const Plug *input, AffectedPlugsContainer &outputs ) c
{
ComputeNode::affects( input, outputs );

const CompoundPlug *in = getChild<CompoundPlug>( "in" );
const ValuePlug *out = getChild<ValuePlug>( "out" );
const CompoundPlug *in = inPlug();
const ValuePlug *out = outPlug();
if( in && out )
{
if( input->parent<CompoundPlug>() == in )
Expand All @@ -127,11 +130,11 @@ void Expression::affects( const Plug *input, AffectedPlugsContainer &outputs ) c
void Expression::hash( const ValuePlug *output, const Context *context, IECore::MurmurHash &h ) const
{
ComputeNode::hash( output, context, h );
if( output == getChild<ValuePlug>( "out" ) )
if( output == outPlug() )
{
enginePlug()->hash( h );
expressionPlug()->hash( h );
const CompoundPlug *in = getChild<CompoundPlug>( "in" );
const CompoundPlug *in = inPlug();
if( in )
{
in->hash( h );
Expand All @@ -156,11 +159,11 @@ void Expression::hash( const ValuePlug *output, const Context *context, IECore::

void Expression::compute( ValuePlug *output, const Context *context ) const
{
if( output == getChild<ValuePlug>( "out" ) )
if( output == outPlug() )
{
if( m_engine )
{
const CompoundPlug *in = getChild<CompoundPlug>( "in" );
const CompoundPlug *in = inPlug();
std::vector<const ValuePlug *> inputs;
for( ChildContainer::const_iterator it = in->children().begin(); it!=in->children().end(); it++ )
{
Expand All @@ -179,6 +182,26 @@ void Expression::compute( ValuePlug *output, const Context *context ) const
ComputeNode::compute( output, context );
}

CompoundPlug *Expression::inPlug()
{
return getChild<CompoundPlug>( g_inPlugName );
}

const CompoundPlug *Expression::inPlug() const
{
return getChild<CompoundPlug>( g_inPlugName );
}

ValuePlug *Expression::outPlug()
{
return getChild<ValuePlug>( g_outPlugName );
}

const ValuePlug *Expression::outPlug() const
{
return getChild<ValuePlug>( g_outPlugName );
}

void Expression::plugSet( Plug *plug )
{
if( !parent<Node>() )
Expand Down Expand Up @@ -246,12 +269,12 @@ void Expression::updatePlugs( const std::string &dstPlugPath, std::vector<std::s
// if the expression was invalid, remove our plugs
if( !dstPlugPath.size() )
{
Plug *in = getChild<Plug>( "in" );
Plug *in = inPlug();
if( in )
{
removeChild( in );
}
Plug *out = getChild<Plug>( "out" );
Plug *out = outPlug();
if( out )
{
removeChild( out );
Expand All @@ -267,8 +290,8 @@ void Expression::updatePlugs( const std::string &dstPlugPath, std::vector<std::s
throw IECore::Exception( boost::str( boost::format( "Destination plug \"%s\" does not exist" ) % dstPlugPath ) );
}

CompoundPlugPtr inPlugs = new CompoundPlug( "in", Plug::In, Plug::Default | Plug::Dynamic );
setChild( "in", inPlugs );
CompoundPlugPtr inPlugs = new CompoundPlug( g_inPlugName, Plug::In, Plug::Default | Plug::Dynamic );
setChild( g_inPlugName, inPlugs );
for( std::vector<std::string>::const_iterator it = srcPlugPaths.begin(); it!=srcPlugPaths.end(); it++ )
{
ValuePlug *srcPlug = p->descendant<ValuePlug>( *it );
Expand All @@ -281,8 +304,8 @@ void Expression::updatePlugs( const std::string &dstPlugPath, std::vector<std::s
inPlug->setInput( srcPlug );
}

PlugPtr outPlug = dstPlug->createCounterpart( "out", Plug::Out );
setChild( "out", outPlug );
PlugPtr outPlug = dstPlug->createCounterpart( g_outPlugName, Plug::Out );
setChild( g_outPlugName, outPlug );
dstPlug->setInput( outPlug );
}

Expand Down

0 comments on commit 1b96bb8

Please sign in to comment.