mirror of
https://github.com/NixOS/nix
synced 2025-06-27 08:31:16 +02:00
* 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.
This commit is contained in:
parent
10e8b1fd15
commit
ac1e8f40d4
15 changed files with 228 additions and 101 deletions
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue