diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx index bce01ab7932be11d144f1e759b4e28a6bfcc1324..ba50634ed769165fab4dc346cd43470f01878727 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx +++ b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx @@ -234,17 +234,12 @@ bool RegExpOptimize::A4( UnboundedRegExpAlternation * const & node ) const { * * As we always sort in optimization, we can use the first version, but A4 must be __always__ called __after__ A2 */ + auto cmp = [ ]( const std::smart_ptr < UnboundedRegExpElement > & a, const std::smart_ptr < UnboundedRegExpElement > & b ) -> bool { return *a == *b; }; - bool optimized = false; - if(node->getChildren ( ).size() != 0) for( auto it = std::next( node->getChildren ( ).begin( ) ); it != node->getChildren ( ).end( ); ) { - if ( ** it == ** std::prev( it ) ) { - it = node->getChildren ( ).erase( it ); - optimized = true; - } else - it ++; - } + size_t size = node->getChildren ( ).size ( ); + std::unique ( node->getChildren ( ).begin ( ), node->getChildren ( ).end ( ), cmp); - return optimized; + return size != node->getChildren ( ).size ( ); } /**