From 66df2aca4dca43f70f65f417d9dea474c7cb40a7 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 19 Jul 2016 10:12:35 +0200 Subject: [PATCH] simplify public functions of regexp optimize --- .../simplify/RegExpOptimizeUnboundedPart.cxx | 44 +++++-------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx index d14bbddfaa..e6fe1e0590 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx +++ b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx @@ -10,35 +10,22 @@ namespace regexp { namespace simplify { void RegExpOptimize::optimize( UnboundedRegExpAlternation & alt ) { - //while( A1( alt ) || A2( alt ) || A3( alt ) || A4( alt ) || A10( alt ) || V2( alt ) || V5( alt ) || V6( alt ) || X1( alt ) ); - UnboundedRegExpElement* optimized = optimizeInner( alt ); - - UnboundedRegExpAlternation * alternationOptimized = dynamic_cast<UnboundedRegExpAlternation *>( optimized ); - if( alternationOptimized ) { - alt = std::move( * alternationOptimized ); - delete alternationOptimized; - } else { - alt = UnboundedRegExpAlternation { }; - alt.appendElement( std::manage_move ( optimized ) ); - } + for( unsigned i = 0; i < alt.getChildren ( ).size ( ); i++ ) + alt.setChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( * alt.getChildren ( ) [ i ] ) ), i ); + + while( A1( alt ) || A2( alt ) || A3( alt ) || A4( alt ) || A10( alt ) || V2( alt ) || V5( alt ) || V6( alt ) || X1( alt ) ); } void RegExpOptimize::optimize( UnboundedRegExpConcatenation & concat ) { - //while( A5( concat ) || A6( concat ) || A7( concat ) || A8( concat ) || A9( concat ) || V8( concat ) );//|| V9( concat ) ); - UnboundedRegExpElement* optimized = optimizeInner( concat ); - - UnboundedRegExpConcatenation * concatenationOptimized = dynamic_cast<UnboundedRegExpConcatenation *>( optimized ); - if( concatenationOptimized ) { - concat = std::move( * concatenationOptimized ); - delete concatenationOptimized; - } else { - concat = UnboundedRegExpConcatenation { }; - concat.appendElement( std::manage_move ( optimized ) ); - } + for( unsigned i = 0; i < concat.getChildren ( ).size ( ); i++ ) + concat.setChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( * concat.getChildren ( ) [ i ] ) ), i ); + + while( A5( concat ) || A6( concat ) || A7( concat ) || A8( concat ) || A9( concat ) || V8( concat ) );//|| V9( concat ) ); } void RegExpOptimize::optimize( UnboundedRegExpIteration & iter ) { - /*do { + iter.setChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner ( * iter.getChild ( ) ) ) ); + do { // V1 is implemented right here if( dynamic_cast<UnboundedRegExpEmpty*>( iter.getChild ( ).get() ) ) { return; @@ -47,16 +34,7 @@ void RegExpOptimize::optimize( UnboundedRegExpIteration & iter ) { if( dynamic_cast<UnboundedRegExpEpsilon*>( iter.getChild ( ).get() ) ) { return; } - } while( A11( iter ) || V1( iter ) || V3( iter ) || V4( iter ) || V10( iter ) );*/ - UnboundedRegExpElement* optimized = optimizeInner( iter ); - - UnboundedRegExpIteration * iterationOptimized = dynamic_cast<UnboundedRegExpIteration *>( optimized ); - if( iterationOptimized ) { - iter = std::move( * iterationOptimized ); - delete iterationOptimized; - } else { - iter = UnboundedRegExpIteration { std::manage_move ( optimized ) }; - } + } while( A11( iter ) || V1( iter ) || V3( iter ) || V4( iter ) || V10( iter ) ); } UnboundedRegExpElement* RegExpOptimize::optimizeInner( const UnboundedRegExpElement & node ) { -- GitLab