From 1b96bb8b1517d60e08b69f9f122f1ac4851645f6 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 14 Oct 2014 13:03:35 +0100 Subject: [PATCH] Removed unnecessary InternedString construction from Expression node. This knocks 6% off the runtime when traversing a cached scene generated by 100 CustomAttributes nodes each with expressions. --- include/Gaffer/Expression.h | 6 +++++ src/Gaffer/Expression.cpp | 47 +++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/include/Gaffer/Expression.h b/include/Gaffer/Expression.h index 1e9b32dab66..15538cc65c5 100644 --- a/include/Gaffer/Expression.h +++ b/include/Gaffer/Expression.h @@ -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 ); diff --git a/src/Gaffer/Expression.cpp b/src/Gaffer/Expression.cpp index 235409665ef..25823786a8e 100644 --- a/src/Gaffer/Expression.cpp +++ b/src/Gaffer/Expression.cpp @@ -48,6 +48,9 @@ using namespace Gaffer; +static IECore::InternedString g_inPlugName( "in" ); +static IECore::InternedString g_outPlugName( "out" ); + ////////////////////////////////////////////////////////////////////////// // Expression implementation ////////////////////////////////////////////////////////////////////////// @@ -106,8 +109,8 @@ void Expression::affects( const Plug *input, AffectedPlugsContainer &outputs ) c { ComputeNode::affects( input, outputs ); - const CompoundPlug *in = getChild( "in" ); - const ValuePlug *out = getChild( "out" ); + const CompoundPlug *in = inPlug(); + const ValuePlug *out = outPlug(); if( in && out ) { if( input->parent() == in ) @@ -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( "out" ) ) + if( output == outPlug() ) { enginePlug()->hash( h ); expressionPlug()->hash( h ); - const CompoundPlug *in = getChild( "in" ); + const CompoundPlug *in = inPlug(); if( in ) { in->hash( h ); @@ -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( "out" ) ) + if( output == outPlug() ) { if( m_engine ) { - const CompoundPlug *in = getChild( "in" ); + const CompoundPlug *in = inPlug(); std::vector inputs; for( ChildContainer::const_iterator it = in->children().begin(); it!=in->children().end(); it++ ) { @@ -179,6 +182,26 @@ void Expression::compute( ValuePlug *output, const Context *context ) const ComputeNode::compute( output, context ); } +CompoundPlug *Expression::inPlug() +{ + return getChild( g_inPlugName ); +} + +const CompoundPlug *Expression::inPlug() const +{ + return getChild( g_inPlugName ); +} + +ValuePlug *Expression::outPlug() +{ + return getChild( g_outPlugName ); +} + +const ValuePlug *Expression::outPlug() const +{ + return getChild( g_outPlugName ); +} + void Expression::plugSet( Plug *plug ) { if( !parent() ) @@ -246,12 +269,12 @@ void Expression::updatePlugs( const std::string &dstPlugPath, std::vector( "in" ); + Plug *in = inPlug(); if( in ) { removeChild( in ); } - Plug *out = getChild( "out" ); + Plug *out = outPlug(); if( out ) { removeChild( out ); @@ -267,8 +290,8 @@ void Expression::updatePlugs( const std::string &dstPlugPath, std::vector::const_iterator it = srcPlugPaths.begin(); it!=srcPlugPaths.end(); it++ ) { ValuePlug *srcPlug = p->descendant( *it ); @@ -281,8 +304,8 @@ void Expression::updatePlugs( const std::string &dstPlugPath, std::vectorsetInput( 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 ); }