Wang et al,

I was looking through the output of one of my serializers and noticed that when 
writing out in ascii, it performs two instances of the get method.  Here is a 
snippet from the string serializer in osgDB/Serializer:

    448     virtual bool write( OutputStream& os, const osg::Object& obj )
    449     {
    450         const C& object = OBJECT_CAST<const C&>(obj);
    451         if ( os.isBinary() )
    452         {
    453             os << (object.*_getter)();
    454         }
    455         else if ( ParentType::_defaultValue!=(object.*_getter)() )
    456         {
    457             os << PROPERTY((ParentType::_name).c_str());
    458             os.writeWrappedString( (object.*_getter)() );
    459             os << std::endl;
    460         }
    461         return true;
    462     }

The (object.*getter)() method call, at least in my case, is a non-trivial 
accessor.  It gets called on line 455 as well as 458.  What do you think about 
adding a temporary between line 450-451 like so:

    448     virtual bool write( OutputStream& os, const osg::Object& obj )
    449     {
    450         const C& object = OBJECT_CAST<const C&>(obj);
                const std::string& value = (object.*_getter)();
    451         if ( os.isBinary() )
    452         {
    453             os << value;
    454         }
    455         else if ( ParentType::_defaultValue!=value )
    456         {
    457             os << PROPERTY((ParentType::_name).c_str());
    458             os.writeWrappedString( value );
    459             os << std::endl;
    460         }
    461         return true;
    462     }

I suppose line 450 and my additional line could be squashed to a single 
expression, but you get the idea.  This will reduce it to a single accessor in 
the ascii case.  This same conversion can be used throughout the rest of the 
serializers as well.
I know you are making changes to some of the serialization code to support 
other classes.  Let me know if you want me to submit a patch, or if you want to 
do this and roll it up with other changes you are making.

Thanks
Chuck
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to