diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-13T12·25+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-13T12·25+0000 |
commit | ac1e8f40d4a5c380d68bb6f1c7cef6f1e7987c1a (patch) | |
tree | bcdb22f27c39948cdb254afd560ac198ae675f56 /src/libexpr/eval-test.cc | |
parent | 10e8b1fd15d59dc541c15f6da56f8baf58eb3aa3 (diff) |
* Use a symbol table to represent identifiers and attribute names
efficiently. The symbol table ensures that there is only one copy of each symbol, thus allowing symbols to be compared efficiently using a pointer equality test.
Diffstat (limited to 'src/libexpr/eval-test.cc')
-rw-r--r-- | src/libexpr/eval-test.cc | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/libexpr/eval-test.cc b/src/libexpr/eval-test.cc index ffadd41a7c7a..d03d3bdeed1b 100644 --- a/src/libexpr/eval-test.cc +++ b/src/libexpr/eval-test.cc @@ -12,7 +12,7 @@ using namespace nix; void doTest(EvalState & state, string s) { - Expr * e = parseExprFromString(s, absPath(".")); + Expr * e = parseExprFromString(state, s, absPath(".")); std::cerr << ">>>>> " << *e << std::endl; Value v; state.eval(e, v); @@ -23,6 +23,29 @@ void doTest(EvalState & state, string s) void run(Strings args) { + SymbolTable t; + + printMsg(lvlError, format("size of symbol: %1% bytes") % sizeof(Symbol)); + + Symbol s1 = t.create("foo"); + Symbol s2 = t.create("foo"); + Symbol s3 = t.create("bar"); + Symbol s4 = t.create("foo"); + + assert(s1 == s2); + assert(s1 == s4); + assert(s1 != s3); + + std::map<Symbol, int> m; + + m[s1] = 123; + m[s3] = 456; + + std::cout << m[s1] << std::endl; + std::cout << m[s2] << std::endl; + std::cout << m[s3] << std::endl; + std::cout << m[s4] << std::endl; + EvalState state; printMsg(lvlError, format("size of value: %1% bytes") % sizeof(Value)); |