From eadd685c7d44342ebee8dc2959cbc1e11187164b Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Fri, 7 Aug 2015 15:26:31 -0400 Subject: [PATCH] parser: eliminate needless probe-point-component token duplication parser::parse_probe_point created a new token unnecessarily, on the off chance that a component had to be extended due to wildcards like probe foo* Now this is done only if necessary, and even then not by creating a new token but rewriting the content of a previous one. --- parse.cxx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/parse.cxx b/parse.cxx index ac16da337..94ea5eb0f 100644 --- a/parse.cxx +++ b/parse.cxx @@ -2360,6 +2360,7 @@ parser::parse_probe_point () // loop which reconstitutes an identifier with wildcards string content = t->content; + bool changed_p = false; while (1) { const token* u = peek(); @@ -2378,14 +2379,19 @@ parser::parse_probe_point () // append u to t content = content + (string)u->content; + changed_p = true; // consume u swallow (); } - // get around const-ness of t: - token* new_t = new token(*t); - new_t->content = content; - delete t; t = new_t; + + if (changed_p) + { + // We've already swallowed the first token and we're not + // putting it back; no one else has a copy; so we can + // safely overwrite its content and reuse it. + const_cast(t)->content = content; + } probe_point::component* c = new probe_point::component; c->functor = t->content; -- 2.43.5