From 6753176d8993cade07a0ea1a3375de930446be9d Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 22 Aug 2014 23:47:54 -0400 Subject: [PATCH] Parser - ::findPattern moves branch pruning out of the iterated loop. --- src/Parser.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index 955edab31..5b7c513be 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -831,8 +831,8 @@ std::string Parser::getCommand () const void Parser::findPattern () { context.debug ("Parser::findPattern"); - bool action = false; + std::vector prune; std::vector nodes; collect (nodes); std::vector ::iterator i; @@ -845,8 +845,8 @@ void Parser::findPattern () pattern.length () > 0) { (*i)->unTag ("?"); - (*i)->removeAllBranches (); (*i)->tag ("PATTERN"); + prune.push_back (*i); Tree* branch = (*i)->addBranch (new Tree ("argPat")); branch->attribute ("raw", "description"); @@ -858,11 +858,14 @@ void Parser::findPattern () branch = (*i)->addBranch (new Tree ("argPat")); branch->attribute ("raw", pattern); branch->tag ("STRING"); - action = true; } } - if (action) + // Prune branches outside the loop. + for (i = prune.begin (); i != prune.end (); ++i) + (*i)->removeAllBranches (); + + if (prune.size ()) context.debug (_tree->dump ()); }