From b681639b2ad5b1e6d49ce5c1de1e63a53416a1a2 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 19 Jul 2016 09:12:18 +0200 Subject: [PATCH] optimize optimisations --- .../simplify/RegExpOptimizeUnboundedPart.cxx | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx index 1fb2421e80..91e93f04f3 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx +++ b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx @@ -783,10 +783,9 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { if( concat->getChildren().begin( ) == itStartX ) { regexpA = new UnboundedRegExpEpsilon( ); } else { - UnboundedRegExpConcatenation* tmpA = new UnboundedRegExpConcatenation( ); - tmpA->insert( tmpA->getChildren().end( ), concat->getChildren().begin( ), itStartX ); - regexpA = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( tmpA ); - delete tmpA; + UnboundedRegExpConcatenation tmpA; + tmpA.insert( tmpA.getChildren().end( ), concat->getChildren().begin( ), itStartX ); + regexpA = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpA ); } // store everything behind iteration's followup element as "y" @@ -794,20 +793,18 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { if( std::next( itC ) == concat->getChildren().end( ) ) { regexpY = new UnboundedRegExpEpsilon( ); } else { - UnboundedRegExpConcatenation* tmpY = new UnboundedRegExpConcatenation( ); - tmpY->insert( tmpY->getChildren().end( ), std::next( itC ), concat->getChildren ( ).end( ) ); - regexpY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( tmpY ); - delete tmpY; + UnboundedRegExpConcatenation tmpY; + tmpY.insert( tmpY.getChildren().end( ), std::next( itC ), concat->getChildren ( ).end( ) ); + regexpY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpY ); } // concatenate "a" and "y" and see if they exist somewhere in parent alternation ( node->getElements() ) - UnboundedRegExpConcatenation* tmpAY = new UnboundedRegExpConcatenation( ); - tmpAY->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) ); - tmpAY->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) ); - UnboundedRegExpElement * regexpAY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( tmpAY ); - regexpA = tmpAY->getChildren()[0].release(); - regexpY = tmpAY->getChildren()[1].release(); - delete tmpAY; + UnboundedRegExpConcatenation tmpAY; + tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) ); + tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) ); + UnboundedRegExpElement * regexpAY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpAY ); + regexpA = tmpAY.getChildren()[0].release(); + regexpY = tmpAY.getChildren()[1].release(); auto iterAY = find_if( node.getChildren().begin( ), node.getChildren().end( ), [ regexpAY ] ( const std::smart_ptr < UnboundedRegExpElement > & a ) -> bool{ return *a == *regexpAY; } ); delete regexpAY; @@ -827,13 +824,11 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { // 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; } ); - UnboundedRegExpConcatenation * tmpAltered = new UnboundedRegExpConcatenation( ); - tmpAltered->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) ); - tmpAltered->pushBackChild( * itC ); - tmpAltered->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) ); - UnboundedRegExpElement * regexpAltered = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( tmpAltered ); - - delete tmpAltered; + UnboundedRegExpConcatenation tmpAltered; + tmpAltered.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) ); + tmpAltered.pushBackChild( * itC ); + tmpAltered.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) ); + UnboundedRegExpElement * regexpAltered = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpAltered ); node.setChild( std::smart_ptr < UnboundedRegExpElement > ( regexpAltered ), itA ); optimized = true; -- GitLab