From 6268d0247412bb498042672a11f3e40e951bdfe5 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Fri, 8 Jul 2016 21:47:49 +0200 Subject: [PATCH] use unique in x+x->x regexp optimisation --- .../regexp/simplify/RegExpOptimizeUnboundedPart.cxx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx index bce01ab793..ba50634ed7 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 ( ); } /** -- GitLab