diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx index 1fb2421e805576565263ad84ad94697f5e4d69a6..91e93f04f34e7f325199c2615fc55c6d00e3a3f3 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;