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

optimize optimisations

parent bbd90d39
No related branches found
No related tags found
No related merge requests found
...@@ -783,10 +783,9 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { ...@@ -783,10 +783,9 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) {
if( concat->getChildren().begin( ) == itStartX ) { if( concat->getChildren().begin( ) == itStartX ) {
regexpA = new UnboundedRegExpEpsilon( ); regexpA = new UnboundedRegExpEpsilon( );
} else { } else {
UnboundedRegExpConcatenation* tmpA = new UnboundedRegExpConcatenation( ); UnboundedRegExpConcatenation tmpA;
tmpA->insert( tmpA->getChildren().end( ), concat->getChildren().begin( ), itStartX ); tmpA.insert( tmpA.getChildren().end( ), concat->getChildren().begin( ), itStartX );
regexpA = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( tmpA ); regexpA = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpA );
delete tmpA;
} }
   
// store everything behind iteration's followup element as "y" // store everything behind iteration's followup element as "y"
...@@ -794,20 +793,18 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { ...@@ -794,20 +793,18 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) {
if( std::next( itC ) == concat->getChildren().end( ) ) { if( std::next( itC ) == concat->getChildren().end( ) ) {
regexpY = new UnboundedRegExpEpsilon( ); regexpY = new UnboundedRegExpEpsilon( );
} else { } else {
UnboundedRegExpConcatenation* tmpY = new UnboundedRegExpConcatenation( ); UnboundedRegExpConcatenation tmpY;
tmpY->insert( tmpY->getChildren().end( ), std::next( itC ), concat->getChildren ( ).end( ) ); tmpY.insert( tmpY.getChildren().end( ), std::next( itC ), concat->getChildren ( ).end( ) );
regexpY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( tmpY ); regexpY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpY );
delete tmpY;
} }
   
// concatenate "a" and "y" and see if they exist somewhere in parent alternation ( node->getElements() ) // concatenate "a" and "y" and see if they exist somewhere in parent alternation ( node->getElements() )
UnboundedRegExpConcatenation* tmpAY = new UnboundedRegExpConcatenation( ); UnboundedRegExpConcatenation tmpAY;
tmpAY->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) ); tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) );
tmpAY->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) ); tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) );
UnboundedRegExpElement * regexpAY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( tmpAY ); UnboundedRegExpElement * regexpAY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpAY );
regexpA = tmpAY->getChildren()[0].release(); regexpA = tmpAY.getChildren()[0].release();
regexpY = tmpAY->getChildren()[1].release(); regexpY = tmpAY.getChildren()[1].release();
delete tmpAY;
   
auto iterAY = find_if( node.getChildren().begin( ), node.getChildren().end( ), [ regexpAY ] ( const std::smart_ptr < UnboundedRegExpElement > & a ) -> bool{ return *a == *regexpAY; } ); auto iterAY = find_if( node.getChildren().begin( ), node.getChildren().end( ), [ regexpAY ] ( const std::smart_ptr < UnboundedRegExpElement > & a ) -> bool{ return *a == *regexpAY; } );
delete regexpAY; delete regexpAY;
...@@ -827,13 +824,11 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { ...@@ -827,13 +824,11 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) {
// iterator invalidated, need to recall before erase // iterator invalidated, need to recall before erase
itA = find_if( node.getChildren().begin( ), node.getChildren().end( ), [ tmpItA ]( const std::smart_ptr < UnboundedRegExpElement > & a ) -> bool { return *a == *tmpItA; } ); itA = find_if( node.getChildren().begin( ), node.getChildren().end( ), [ tmpItA ]( const std::smart_ptr < UnboundedRegExpElement > & a ) -> bool { return *a == *tmpItA; } );
   
UnboundedRegExpConcatenation * tmpAltered = new UnboundedRegExpConcatenation( ); UnboundedRegExpConcatenation tmpAltered;
tmpAltered->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) ); tmpAltered.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) );
tmpAltered->pushBackChild( * itC ); tmpAltered.pushBackChild( * itC );
tmpAltered->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) ); tmpAltered.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) );
UnboundedRegExpElement * regexpAltered = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( tmpAltered ); UnboundedRegExpElement * regexpAltered = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpAltered );
delete tmpAltered;
   
node.setChild( std::smart_ptr < UnboundedRegExpElement > ( regexpAltered ), itA ); node.setChild( std::smart_ptr < UnboundedRegExpElement > ( regexpAltered ), itA );
optimized = true; optimized = true;
......
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