AbstractClassRep *AbstractClassRep::getCommonParent( const AbstractClassRep *otherClass ) const { // CodeReview: This may be a noob way of doing it. There may be some kind of // super-spiffy algorithm to do what the code below does, but this appeared // to make sense to me, and it is pretty easy to see what it is doing [6/23/2007 Pat] static VectorPtr<AbstractClassRep *> thisClassHeirarchy; thisClassHeirarchy.clear(); AbstractClassRep *walk = const_cast<AbstractClassRep *>( this ); while( walk != NULL ) { thisClassHeirarchy.push_front( walk ); walk = walk->getParentClass(); } static VectorPtr<AbstractClassRep *> compClassHeirarchy; compClassHeirarchy.clear(); walk = const_cast<AbstractClassRep *>( otherClass ); while( walk != NULL ) { compClassHeirarchy.push_front( walk ); walk = walk->getParentClass(); } // Make sure we only iterate over the list the number of times we can S32 maxIterations = getMin( compClassHeirarchy.size(), thisClassHeirarchy.size() ); U32 i = 0; for( ; i < maxIterations; i++ ) { if( compClassHeirarchy[i] != thisClassHeirarchy[i] ) break; } return compClassHeirarchy[i]; }