Merge branch 'perf-fixes' of git://github.com/dezgeg/nix

This commit is contained in:
Shea Levy 2018-02-19 10:11:52 -05:00
commit e1eb63a586
No known key found for this signature in database
GPG key ID: 5C0BD6957D86FE27
5 changed files with 30 additions and 27 deletions

View file

@ -7,13 +7,14 @@
namespace nix { namespace nix {
/* Note: Various places expect the allocated memory to be zeroed. */
static void * allocBytes(size_t n) static void * allocBytes(size_t n)
{ {
void * p; void * p;
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
p = GC_malloc(n); p = GC_malloc(n);
#else #else
p = malloc(n); p = calloc(n, 1);
#endif #endif
if (!p) throw std::bad_alloc(); if (!p) throw std::bad_alloc();
return p; return p;

View file

@ -43,13 +43,14 @@ static char * dupString(const char * s)
} }
/* Note: Various places expect the allocated memory to be zeroed. */
static void * allocBytes(size_t n) static void * allocBytes(size_t n)
{ {
void * p; void * p;
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
p = GC_malloc(n); p = GC_malloc(n);
#else #else
p = malloc(n); p = calloc(n, 1);
#endif #endif
if (!p) throw std::bad_alloc(); if (!p) throw std::bad_alloc();
return p; return p;
@ -293,6 +294,10 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store)
, sWrong(symbols.create("wrong")) , sWrong(symbols.create("wrong"))
, sStructuredAttrs(symbols.create("__structuredAttrs")) , sStructuredAttrs(symbols.create("__structuredAttrs"))
, sBuilder(symbols.create("builder")) , sBuilder(symbols.create("builder"))
, sArgs(symbols.create("args"))
, sOutputHash(symbols.create("outputHash"))
, sOutputHashAlgo(symbols.create("outputHashAlgo"))
, sOutputHashMode(symbols.create("outputHashMode"))
, repair(NoRepair) , repair(NoRepair)
, store(store) , store(store)
, baseEnv(allocEnv(128)) , baseEnv(allocEnv(128))
@ -582,9 +587,7 @@ Env & EvalState::allocEnv(unsigned int size)
Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *)); Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *));
env->size = size; env->size = size;
/* Clear the values because maybeThunk() and lookupVar fromWith expect this. */ /* We assume that env->values has been cleared by the allocator; maybeThunk() and lookupVar fromWith expect this. */
for (unsigned i = 0; i < size; ++i)
env->values[i] = 0;
return *env; return *env;
} }

View file

@ -69,7 +69,8 @@ public:
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue, const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue,
sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls, sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls,
sFile, sLine, sColumn, sFunctor, sToString, sFile, sLine, sColumn, sFunctor, sToString,
sRight, sWrong, sStructuredAttrs, sBuilder; sRight, sWrong, sStructuredAttrs, sBuilder, sArgs,
sOutputHash, sOutputHashAlgo, sOutputHashMode;
Symbol sDerivationNix; Symbol sDerivationNix;
/* If set, force copying files to the Nix store even if they /* If set, force copying files to the Nix store even if they

View file

@ -49,9 +49,10 @@ static void adjustLoc(YYLTYPE * loc, const char * s, size_t len)
} }
static Expr * unescapeStr(SymbolTable & symbols, const char * s) static Expr * unescapeStr(SymbolTable & symbols, const char * s, size_t length)
{ {
string t; string t;
t.reserve(length);
char c; char c;
while ((c = *s++)) { while ((c = *s++)) {
if (c == '\\') { if (c == '\\') {
@ -150,7 +151,7 @@ or { return OR_KW; }
/* It is impossible to match strings ending with '$' with one /* It is impossible to match strings ending with '$' with one
regex because trailing contexts are only valid at the end regex because trailing contexts are only valid at the end
of a rule. (A sane but undocumented limitation.) */ of a rule. (A sane but undocumented limitation.) */
yylval->e = unescapeStr(data->symbols, yytext); yylval->e = unescapeStr(data->symbols, yytext, yyleng);
return STR; return STR;
} }
<STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; } <STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
@ -178,7 +179,7 @@ or { return OR_KW; }
return IND_STR; return IND_STR;
} }
<IND_STRING>\'\'\\. { <IND_STRING>\'\'\\. {
yylval->e = unescapeStr(data->symbols, yytext + 2); yylval->e = unescapeStr(data->symbols, yytext + 2, yyleng - 2);
return IND_STR; return IND_STR;
} }
<IND_STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; } <IND_STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }

View file

@ -553,7 +553,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
for (auto & i : args[0]->attrs->lexicographicOrder()) { for (auto & i : args[0]->attrs->lexicographicOrder()) {
if (i->name == state.sIgnoreNulls) continue; if (i->name == state.sIgnoreNulls) continue;
string key = i->name; const string & key = i->name;
vomit("processing attribute '%1%'", key); vomit("processing attribute '%1%'", key);
auto handleHashMode = [&](const std::string & s) { auto handleHashMode = [&](const std::string & s) {
@ -589,7 +589,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
/* The `args' attribute is special: it supplies the /* The `args' attribute is special: it supplies the
command-line arguments to the builder. */ command-line arguments to the builder. */
if (key == "args") { if (i->name == state.sArgs) {
state.forceList(*i->value, pos); state.forceList(*i->value, pos);
for (unsigned int n = 0; n < i->value->listSize(); ++n) { for (unsigned int n = 0; n < i->value->listSize(); ++n) {
string s = state.coerceToString(posDrvName, *i->value->listElems()[n], context, true); string s = state.coerceToString(posDrvName, *i->value->listElems()[n], context, true);
@ -612,15 +612,13 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
drv.builder = state.forceString(*i->value, context, posDrvName); drv.builder = state.forceString(*i->value, context, posDrvName);
else if (i->name == state.sSystem) else if (i->name == state.sSystem)
drv.platform = state.forceStringNoCtx(*i->value, posDrvName); drv.platform = state.forceStringNoCtx(*i->value, posDrvName);
else if (i->name == state.sName) else if (i->name == state.sOutputHash)
drvName = state.forceStringNoCtx(*i->value, posDrvName);
else if (key == "outputHash")
outputHash = state.forceStringNoCtx(*i->value, posDrvName); outputHash = state.forceStringNoCtx(*i->value, posDrvName);
else if (key == "outputHashAlgo") else if (i->name == state.sOutputHashAlgo)
outputHashAlgo = state.forceStringNoCtx(*i->value, posDrvName); outputHashAlgo = state.forceStringNoCtx(*i->value, posDrvName);
else if (key == "outputHashMode") else if (i->name == state.sOutputHashMode)
handleHashMode(state.forceStringNoCtx(*i->value, posDrvName)); handleHashMode(state.forceStringNoCtx(*i->value, posDrvName));
else if (key == "outputs") { else if (i->name == state.sOutputs) {
/* Require outputs to be a list of strings. */ /* Require outputs to be a list of strings. */
state.forceList(*i->value, posDrvName); state.forceList(*i->value, posDrvName);
Strings ss; Strings ss;
@ -634,14 +632,10 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
drv.env.emplace(key, s); drv.env.emplace(key, s);
if (i->name == state.sBuilder) drv.builder = s; if (i->name == state.sBuilder) drv.builder = s;
else if (i->name == state.sSystem) drv.platform = s; else if (i->name == state.sSystem) drv.platform = s;
else if (i->name == state.sName) { else if (i->name == state.sOutputHash) outputHash = s;
drvName = s; else if (i->name == state.sOutputHashAlgo) outputHashAlgo = s;
printMsg(lvlVomit, format("derivation name is '%1%'") % drvName); else if (i->name == state.sOutputHashMode) handleHashMode(s);
} else if (i->name == state.sOutputs)
else if (key == "outputHash") outputHash = s;
else if (key == "outputHashAlgo") outputHashAlgo = s;
else if (key == "outputHashMode") handleHashMode(s);
else if (key == "outputs")
handleOutputs(tokenizeString<Strings>(s)); handleOutputs(tokenizeString<Strings>(s));
} }
@ -1138,8 +1132,11 @@ static void prim_attrNames(EvalState & state, const Pos & pos, Value * * args, V
state.mkList(v, args[0]->attrs->size()); state.mkList(v, args[0]->attrs->size());
size_t n = 0; size_t n = 0;
for (auto & i : args[0]->attrs->lexicographicOrder()) for (auto & i : *args[0]->attrs)
mkString(*(v.listElems()[n++] = state.allocValue()), i->name); mkString(*(v.listElems()[n++] = state.allocValue()), i.name);
std::sort(v.listElems(), v.listElems() + n,
[](Value * v1, Value * v2) { return strcmp(v1->string.s, v2->string.s) < 0; });
} }