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

direct constr. of some tmp regexps in optimisation

parent d73247a2
No related branches found
No related tags found
No related merge requests found
......@@ -588,7 +588,7 @@ bool RegExpOptimize::V5( UnboundedRegExpAlternation & node ) {
UnboundedRegExpConcatenation * iterConcat = dynamic_cast<UnboundedRegExpConcatenation*>( iter->getChild().get() );
 
if( iterConcat->getChildren().size( ) != ( unsigned ) distance( std::next( itC ), concat->getChildren().end( ) )
|| ! equal( iterConcat->getChildren().begin( ), iterConcat->getChildren().end( ), std::next( itC ),
|| ! equal( iterConcat->getChildren().begin( ), iterConcat->getChildren().end( ), std::next( itC ),
[ ]( const std::smart_ptr < UnboundedRegExpElement > & a, const std::smart_ptr < UnboundedRegExpElement > & b ) -> bool{ return *a == *b; } ) ) {
itC++;
continue;
......@@ -604,29 +604,25 @@ bool RegExpOptimize::V5( UnboundedRegExpAlternation & node ) {
}
 
// store everything before iteration as "a"
UnboundedRegExpElement * regexpA;
UnboundedRegExpConcatenation tmpAY;
if( concat->getChildren().begin( ) == itC ) {
regexpA = new UnboundedRegExpEpsilon( );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( new UnboundedRegExpEpsilon( ) ) );
} else {
UnboundedRegExpConcatenation tmpA;
tmpA.insert( tmpA.getChildren().end( ), concat->getChildren().begin( ), itC );
regexpA = optimizeInner( tmpA );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( tmpA ) ) );
}
 
// store everything behind iteration's followup element as "y"
UnboundedRegExpElement * regexpY;
if( itStartY == concat->getChildren().end( ) ) {
regexpY = new UnboundedRegExpEpsilon( );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( new UnboundedRegExpEpsilon( ) ) );
} else {
UnboundedRegExpConcatenation tmpY;
tmpY.insert( tmpY.getChildren().end( ), itStartY, concat->getChildren().end( ) );
regexpY = optimizeInner( tmpY );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( tmpY ) ) );
}
 
// concatenate "a" and "y" and see if they exist somewhere in parent alternation ( node.getChildren() )
UnboundedRegExpConcatenation tmpAY;
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) );
UnboundedRegExpElement * regexpAY = optimizeInner( tmpAY );
 
auto iterAY = find_if( node.getChildren().begin( ), node.getChildren().end( ), [ regexpAY ] ( const std::smart_ptr < UnboundedRegExpElement > & a ) -> bool{ return *a == *regexpAY; } );
......@@ -710,30 +706,24 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) {
advance( itStartX, -1 );
}
 
// store everything before x as "a"
UnboundedRegExpElement * regexpA;
// concatenate "a" and "y" and see if they exist somewhere in parent alternation ( node->getChildren() )
UnboundedRegExpConcatenation tmpAY;
if( concat->getChildren().begin( ) == itStartX ) {
regexpA = new UnboundedRegExpEpsilon( );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( new UnboundedRegExpEpsilon( ) ) );
} else {
UnboundedRegExpConcatenation tmpA;
tmpA.insert( tmpA.getChildren().end( ), concat->getChildren().begin( ), itStartX );
regexpA = optimizeInner( tmpA );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( tmpA ) ) );
}
 
// store everything behind iteration's followup element as "y"
UnboundedRegExpElement * regexpY;
if( std::next( itC ) == concat->getChildren().end( ) ) {
regexpY = new UnboundedRegExpEpsilon( );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( new UnboundedRegExpEpsilon( ) ) );
} else {
UnboundedRegExpConcatenation tmpY;
tmpY.insert( tmpY.getChildren().end( ), std::next( itC ), concat->getChildren ( ).end( ) );
regexpY = optimizeInner( tmpY );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( tmpY ) ) );
}
 
// concatenate "a" and "y" and see if they exist somewhere in parent alternation ( node->getChildren() )
UnboundedRegExpConcatenation tmpAY;
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) );
tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) );
UnboundedRegExpElement * regexpAY = optimizeInner( tmpAY );
 
auto iterAY = find_if( node.getChildren().begin( ), node.getChildren().end( ), [ regexpAY ] ( const std::smart_ptr < UnboundedRegExpElement > & a ) -> bool{ return *a == *regexpAY; } );
......@@ -744,10 +734,12 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) {
continue;
}
 
// if so make a x* y and replace a x x* y
tmpAY.insert( tmpAY.getChildren ( ).begin ( ) + 1, * itC );
 
node.setChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( tmpAY ) ), itA );
 
// remove a y
itA = node.getChildren().erase( iterAY );
 
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