Skip to content
Snippets Groups Projects
Commit 6268d024 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

use unique in x+x->x regexp optimisation

parent edb3c71a
No related branches found
No related tags found
No related merge requests found
......@@ -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 ( );
}
 
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment