Deduplicate filenames in Pos

This saves ~4 MiB of RAM for NixOS system instantiation, and ~18 MiB
for "nix-env -qa".
This commit is contained in:
Eelco Dolstra 2013-10-08 15:19:59 +02:00
parent b1e3b1a4ac
commit 9deb822180
3 changed files with 7 additions and 6 deletions

View file

@ -636,7 +636,6 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
if (state.countCalls && pos) state.attrSelects[*pos]++; if (state.countCalls && pos) state.attrSelects[*pos]++;
} }
state.forceValue(*vAttrs); state.forceValue(*vAttrs);
} catch (Error & e) { } catch (Error & e) {

View file

@ -23,14 +23,16 @@ MakeError(UndefinedVarError, Error)
struct Pos struct Pos
{ {
string file; Symbol file;
unsigned int line, column; unsigned int line, column;
Pos() : line(0), column(0) { }; Pos() : line(0), column(0) { };
Pos(const string & file, unsigned int line, unsigned int column) Pos(const Symbol & file, unsigned int line, unsigned int column)
: file(file), line(line), column(column) { }; : file(file), line(line), column(column) { };
bool operator < (const Pos & p2) const bool operator < (const Pos & p2) const
{ {
int d = file.compare(p2.file); if (!line) return p2.line;
if (!p2.line) return false;
int d = ((string) file).compare((string) p2.file);
if (d < 0) return true; if (d < 0) return true;
if (d > 0) return false; if (d > 0) return false;
if (line < p2.line) return true; if (line < p2.line) return true;

View file

@ -29,7 +29,7 @@ namespace nix {
SymbolTable & symbols; SymbolTable & symbols;
Expr * result; Expr * result;
Path basePath; Path basePath;
Path path; Symbol path;
string error; string error;
Symbol sLetBody; Symbol sLetBody;
ParseData(EvalState & state) ParseData(EvalState & state)
@ -486,7 +486,7 @@ Expr * EvalState::parse(const char * text,
yyscan_t scanner; yyscan_t scanner;
ParseData data(*this); ParseData data(*this);
data.basePath = basePath; data.basePath = basePath;
data.path = path; data.path = data.symbols.create(path);
yylex_init(&scanner); yylex_init(&scanner);
yy_scan_string(text, scanner); yy_scan_string(text, scanner);