[C++] Remove unnecessary allocation for SimpleVar
diff --git a/eval.cc b/eval.cc
index f21e185..3dfc0e6 100644
--- a/eval.cc
+++ b/eval.cc
@@ -54,9 +54,12 @@
Var* rhs = NULL;
bool needs_assign = true;
switch (op) {
- case AssignOp::COLON_EQ:
- rhs = new SimpleVar(rhs_v->Eval(this), origin);
+ case AssignOp::COLON_EQ: {
+ SimpleVar* sv = new SimpleVar(origin);
+ rhs_v->Eval(this, sv->mutable_value());
+ rhs = sv;
break;
+ }
case AssignOp::EQ:
rhs = new RecursiveVar(rhs_v, origin, orig_rhs);
break;
diff --git a/var.cc b/var.cc
index d21dc4f..9fac956 100644
--- a/var.cc
+++ b/var.cc
@@ -47,6 +47,10 @@
CHECK(false);
}
+SimpleVar::SimpleVar(VarOrigin origin)
+ : origin_(origin) {
+}
+
SimpleVar::SimpleVar(const string& v, VarOrigin origin)
: v_(v), origin_(origin) {
}
diff --git a/var.h b/var.h
index 3bae262..c3bb233 100644
--- a/var.h
+++ b/var.h
@@ -62,6 +62,7 @@
class SimpleVar : public Var {
public:
+ explicit SimpleVar(VarOrigin origin);
SimpleVar(const string& v, VarOrigin origin);
virtual const char* Flavor() const {
@@ -79,6 +80,8 @@
virtual string DebugString() const override;
+ string* mutable_value() { return &v_; }
+
private:
string v_;
VarOrigin origin_;