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

unbounded regexp optimisation improvements

parent e238c4f8
No related branches found
No related tags found
No related merge requests found
...@@ -590,7 +590,7 @@ bool RegExpOptimize::V5( UnboundedRegExpAlternation & node ) { ...@@ -590,7 +590,7 @@ bool RegExpOptimize::V5( UnboundedRegExpAlternation & node ) {
if( iterConcat->getChildren().size( ) != ( unsigned ) distance( std::next( itC ), concat->getChildren().end( ) ) 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; } ) ) { [ ]( const std::smart_ptr < UnboundedRegExpElement > & a, const std::smart_ptr < UnboundedRegExpElement > & b ) -> bool{ return *a == *b; } ) ) {
itC++; ++ itC;
continue; continue;
} }
advance( itStartY, (int)iterConcat->getChildren().size( ) ); advance( itStartY, (int)iterConcat->getChildren().size( ) );
...@@ -769,7 +769,7 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation & node ) { ...@@ -769,7 +769,7 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation & node ) {
UnboundedRegExpIteration* iter = dynamic_cast<UnboundedRegExpIteration*>( it->get() ); UnboundedRegExpIteration* iter = dynamic_cast<UnboundedRegExpIteration*>( it->get() );
   
if( ! iter ) { if( ! iter ) {
it ++; ++ it;
continue; continue;
} }
   
...@@ -818,64 +818,58 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation & node ) { ...@@ -818,64 +818,58 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation & node ) {
* @param node UnboundedRegExpConcatenation node * @param node UnboundedRegExpConcatenation node
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
bool RegExpOptimize::V9( UnboundedRegExpConcatenation & /* node */ ) { bool RegExpOptimize::V9( UnboundedRegExpConcatenation & node ) {
/* bool optimized = false; */ bool optimized = false;
   
// interpretation: if concat (C1) with iter && iteration's element is concat (C2), then: // interpretation: if concat (C1) with iter && iteration's element is concat (C2), then:
// simultaneously iterate through C1 and C2. (axy)*axz=ax(yax)*z -> get ax that is same and relocate them... // simultaneously iterate through C1 and C2. (axy)*axz=ax(yax)*z -> get ax that is same and relocate them...
   
/* for( auto it = node->elements.begin( ) ; it != node->elements.end( ) ; ) for( auto it = node.getChildren().begin( ) ; it != node.getChildren().end( ) ; ) {
{
UnboundedRegExpIteration * iter = dynamic_cast<UnboundedRegExpIteration*>( it->get() ); UnboundedRegExpIteration * iter = dynamic_cast<UnboundedRegExpIteration*>( it->get() );
if ( ! iter ) if ( ! iter ) {
{ ++ it;
it++;
continue; continue;
} }
UnboundedRegExpConcatenation * concat = dynamic_cast<UnboundedRegExpConcatenation*>( iter->element.get() ); UnboundedRegExpConcatenation * concat = dynamic_cast<UnboundedRegExpConcatenation*>( iter->getChild().get() );
if( ! concat ) if( ! concat ) {
{ ++it;
it++;
continue; continue;
} }
   
// find range from <it+1;sth> and <concat.begin;sth> that is equal // find range from <it+1;sth> and <concat.begin;sth> that is equal
auto c1Iter = std::next( it ), c2Iter = concat->elements.begin( ); auto c1Iter = std::next( it ), c2Iter = concat->getChildren().begin( );
while( c1Iter != node->elements.end() && c2Iter != concat->elements.end( ) && **c1Iter == ** c2Iter ) while( c1Iter != node.getChildren().end() && c2Iter != concat->getChildren().end( ) && **c1Iter == ** c2Iter ) {
{ ++ c1Iter;
c1Iter ++; ++ c2Iter;
c2Iter ++;
} }
   
if( c1Iter == std::next( it ) ) if( c1Iter == std::next( it ) ) {
{ ++ it;
it ++;
continue; continue;
} }
   
// std::cout << "xy" << std::endl; // std::cout << "xy" << std::endl;
// UnboundedRegExpConcatenation* tmp = new UnboundedRegExpConcatenation( ); // UnboundedRegExpConcatenation* tmp = new UnboundedRegExpConcatenation( );
// tmp->elements.insert( tmp->elements.end( ), std::next( it ), c1Iter ); // tmp->insert( tmp->getChildren().end( ), std::next( it ), c1Iter );
// std::cout << RegExp( tmp ) << std::endl; // std::cout << RegExp( tmp ) << std::endl;
   
// copy the range <it;sth>, delete it and go back to the iter node // copy the range <it;sth>, delete it and go back to the iter node
std::vector<std::smart_ptr < UnboundedRegExpElement > > copyRange; std::vector<std::smart_ptr < UnboundedRegExpElement > > copyRange;
copyRange.insert( copyRange.end(), std::next( it ), c1Iter ); copyRange.insert( copyRange.end(), std::next( it ), c1Iter );
it = node->elements.erase( std::next( it ), c1Iter ); it = node.getChildren().erase( std::next( it ), c1Iter );
it = std::prev( it ); it = std::prev( it );
   
// insert that range before it position // insert that range before it position
node->elements.insert( it, copyRange.begin( ), copyRange.end( ) ); node.insert( it, copyRange.begin( ), copyRange.end( ) );
   
// alter the iteration's concat node // alter the iteration's concat node
copyRange.clear( ); copyRange.clear( );
copyRange.insert( copyRange.end(), concat->elements.begin( ), c2Iter ); copyRange.insert( copyRange.end(), concat->getChildren().begin( ), c2Iter );
concat->elements.erase( concat->elements.begin( ), c2Iter ); concat->getChildren().erase( concat->getChildren().begin( ), c2Iter );
concat->elements.insert( concat->elements.end(), copyRange.begin( ), copyRange.end( ) ); concat->insert( concat->getChildren().end(), copyRange.begin( ), copyRange.end( ) );
} }
   
return optimized; */ return optimized;
return false; // FIXME
} }
   
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment