about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2012-01-07T17·26+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2012-01-07T17·26+0000
commit9fe24c5a0d1e694c6338d584a101034cfbff10bf (patch)
treef938de94275a6a3337a60a111c0c74cd15fb6991 /src/libexpr/eval.cc
parentd4e6b9f2d62ef77ff46397bd130350f03723ce50 (diff)
* Don't create thunks for simple constants (integers, strings, paths)
  and allocate them only once.
* Move Value and related functions into value.hh.

Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index c58b95126833..1e3f42edcc42 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -283,9 +283,7 @@ LocalNoInline(void addErrorPrefix(Error & e, const char * s, const string & s2,
 
 void mkString(Value & v, const char * s)
 {
-    v.type = tString;
-    v.string.s = GC_STRDUP(s);
-    v.string.context = 0;
+    mkStringNoCopy(v, GC_STRDUP(s));
 }
 
 
@@ -303,19 +301,9 @@ void mkString(Value & v, const string & s, const PathSet & context)
 }
 
 
-void mkString(Value & v, const Symbol & s)
-{
-    v.type = tString;
-    v.string.s = ((string) s).c_str();
-    v.string.context = 0;
-}
-
-
 void mkPath(Value & v, const char * s)
 {
-    clearValue(v);
-    v.type = tPath;
-    v.path = GC_STRDUP(s);
+    mkPathNoCopy(v, GC_STRDUP(s));
 }
 
 
@@ -426,6 +414,26 @@ Value * ExprVar::maybeThunk(EvalState & state, Env & env)
 }
 
 
+Value * ExprString::maybeThunk(EvalState & state, Env & env)
+{
+    nrAvoided++;
+    return &v;
+}
+
+Value * ExprInt::maybeThunk(EvalState & state, Env & env)
+{
+    nrAvoided++;
+    return &v;
+}
+
+Value * ExprPath::maybeThunk(EvalState & state, Env & env)
+{
+    nrAvoided++;
+    return &v;
+}
+
+
+
 void EvalState::evalFile(const Path & path, Value & v)
 {
     FileEvalCache::iterator i = fileEvalCache.find(path);
@@ -454,7 +462,7 @@ struct RecursionCounter
             state.maxRecursionDepth = state.recursionDepth;
     }
     ~RecursionCounter()
-    {   
+    {
         state.recursionDepth--;
     }
 };
@@ -512,19 +520,19 @@ void Expr::eval(EvalState & state, Env & env, Value & v)
 
 void ExprInt::eval(EvalState & state, Env & env, Value & v)
 {
-    mkInt(v, n);
+    v = this->v;
 }
 
 
 void ExprString::eval(EvalState & state, Env & env, Value & v)
 {
-    mkString(v, s);
+    v = this->v;
 }
 
 
 void ExprPath::eval(EvalState & state, Env & env, Value & v)
 {
-    mkPath(v, s.c_str());
+    v = this->v;
 }