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

reimplement V8 unbounded regexp optimisation pattern

parent 8bffc1d9
No related branches found
No related tags found
No related merge requests found
...@@ -766,16 +766,16 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation < SymbolType > & /* node */ ...@@ -766,16 +766,16 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation < SymbolType > & /* node */
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V8( UnboundedRegExpConcatenation < SymbolType > & /* node */ ) { bool RegExpOptimize::V8( UnboundedRegExpConcatenation < SymbolType > & node ) {
bool optimized = false; bool optimized = false;
   
// interpretation: if there is iteration in concatenation node, and element of iteration contains eps and is straight before this iteration, then this element can be omitted // interpretation: if there is iteration in concatenation node, and element of iteration contains eps and is straight before this iteration, then this element can be omitted
   
/*if ( node.getChildren ( ).size ( ) == 0 ) if ( node.getChildren ( ).size ( ) == 0 )
return false; return false;
   
for( auto it = next ( node.getChildren ( ).begin( ) ); it != node.getChildren ( ).end( ); ) { for( auto it = node.getChildren ( ).begin( ); it != node.getChildren ( ).end( ); ) {
UnboundedRegExpIteration < SymbolType > * iter = dynamic_cast < UnboundedRegExpIteration < SymbolType > * > ( & * it ); const UnboundedRegExpIteration < SymbolType > * iter = dynamic_cast < const UnboundedRegExpIteration < SymbolType > * > ( & * it );
   
if( ! iter ) { if( ! iter ) {
++ it; ++ it;
...@@ -783,7 +783,7 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation < SymbolType > & /* node * ...@@ -783,7 +783,7 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation < SymbolType > & /* node *
} }
   
// if element of iteration is concatenation, we need to check this specially // if element of iteration is concatenation, we need to check this specially
UnboundedRegExpConcatenation < SymbolType > * concat = dynamic_cast < UnboundedRegExpConcatenation < SymbolType > * > ( & iter->getChild ( ) ); const UnboundedRegExpConcatenation < SymbolType > * concat = dynamic_cast < const UnboundedRegExpConcatenation < SymbolType > * > ( & iter->getChild ( ) );
   
if( concat ) { if( concat ) {
// check if not out of bounds // check if not out of bounds
...@@ -800,23 +800,25 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation < SymbolType > & /* node * ...@@ -800,23 +800,25 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation < SymbolType > & /* node *
equal ( concat->getChildren ( ).begin( ), concat->getChildren ( ).end( ), it2, [ ] ( const UnboundedRegExpElement < SymbolType > & a, const UnboundedRegExpElement < SymbolType > & b ) -> bool { return a == b; } ) ) { equal ( concat->getChildren ( ).begin( ), concat->getChildren ( ).end( ), it2, [ ] ( const UnboundedRegExpElement < SymbolType > & a, const UnboundedRegExpElement < SymbolType > & b ) -> bool { return a == b; } ) ) {
optimized = true; optimized = true;
   
it = node.getChildren ( ).erase ( it2, it ); it = node.erase ( it2, it );
} else } else
++ it; ++ it;
} else { } else {
// check if not at the first node
if ( it == node.getChildren ( ).begin ( ) ) {
it ++;
continue;
}
auto prev = std::prev ( it ); auto prev = std::prev ( it );
   
if ( regexp::properties::RegExpEpsilon::languageContainsEpsilon ( iter->getElement ( ) ) && iter->getElement ( ) == * prev ) { if ( regexp::properties::RegExpEpsilon::languageContainsEpsilon ( iter->getElement ( ) ) && iter->getElement ( ) == * prev ) {
it = node.getChildren ( ).erase ( prev ); it = node.erase ( prev );
optimized = true; optimized = true;
// in case xxx*, we need to stay on the iter element, not to go behind it
if( it != node.getChildren().begin( ) )
it = std::prev( it );
} else } else
++ it; ++ it;
} }
}*/ }
   
return optimized; return optimized;
} }
......
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