chore(3p/nix/libexpr): Minor readability improvements in eval/value

This commit is contained in:
Vincent Ambo 2020-05-23 04:43:16 +01:00
parent 92792264f7
commit da4ca4e02f
4 changed files with 7 additions and 19 deletions

View file

@ -21,7 +21,7 @@ struct Attr {
Attr(Symbol name, Value* value, Pos* pos = &noPos) Attr(Symbol name, Value* value, Pos* pos = &noPos)
: name(name), value(value), pos(pos){}; : name(name), value(value), pos(pos){};
Attr() : pos(&noPos){}; Attr() : pos(&noPos){};
bool operator<(const Attr& a) const { return name < a.name; } bool operator<(const Attr& other) const { return name < other.name; }
}; };
// TODO: remove this, it only exists briefly while I get rid of the // TODO: remove this, it only exists briefly while I get rid of the

View file

@ -815,8 +815,8 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& value) {
size_t displ = 0; size_t displ = 0;
for (auto& attr : attrs) { for (auto& attr : attrs) {
Value* vAttr; Value* vAttr;
vAttr = attr.second.e->maybeThunk(state, vAttr =
attr.second.inherited ? env : env2); attr.second.e->maybeThunk(state, attr.second.inherited ? env : env2);
env2.values[displ++] = vAttr; env2.values[displ++] = vAttr;
value.attrs->push_back(Attr(attr.first, vAttr, &attr.second.pos)); value.attrs->push_back(Attr(attr.first, vAttr, &attr.second.pos));
} }

View file

@ -53,6 +53,10 @@ typedef std::list<SearchPathElem> SearchPath;
/* Initialise the Boehm GC, if applicable. */ /* Initialise the Boehm GC, if applicable. */
void initGC(); void initGC();
typedef std::map<Path, Expr*, std::less<Path>,
traceable_allocator<std::pair<const Path, Expr*>>>
FileParseCache;
class EvalState { class EvalState {
public: public:
SymbolTable symbols; SymbolTable symbols;
@ -79,23 +83,12 @@ class EvalState {
SrcToStore srcToStore; SrcToStore srcToStore;
/* A cache from path names to parse trees. */ /* A cache from path names to parse trees. */
#if HAVE_BOEHMGC
typedef std::map<Path, Expr*, std::less<Path>,
traceable_allocator<std::pair<const Path, Expr*>>>
FileParseCache;
#else
typedef std::map<Path, Expr*> FileParseCache;
#endif
FileParseCache fileParseCache; FileParseCache fileParseCache;
/* A cache from path names to values. */ /* A cache from path names to values. */
#if HAVE_BOEHMGC
typedef std::map<Path, Value, std::less<Path>, typedef std::map<Path, Value, std::less<Path>,
traceable_allocator<std::pair<const Path, Value>>> traceable_allocator<std::pair<const Path, Value>>>
FileEvalCache; FileEvalCache;
#else
typedef std::map<Path, Value> FileEvalCache;
#endif
FileEvalCache fileEvalCache; FileEvalCache fileEvalCache;
SearchPath searchPath; SearchPath searchPath;

View file

@ -244,14 +244,9 @@ void mkPath(Value& v, const char* s);
not included. */ not included. */
size_t valueSize(Value& v); size_t valueSize(Value& v);
#if HAVE_BOEHMGC
typedef std::vector<Value*, gc_allocator<Value*> > ValueVector; typedef std::vector<Value*, gc_allocator<Value*> > ValueVector;
typedef std::map<Symbol, Value*, std::less<Symbol>, typedef std::map<Symbol, Value*, std::less<Symbol>,
gc_allocator<std::pair<const Symbol, Value*> > > gc_allocator<std::pair<const Symbol, Value*> > >
ValueMap; ValueMap;
#else
typedef std::vector<Value*> ValueVector;
typedef std::map<Symbol, Value*> ValueMap;
#endif
} // namespace nix } // namespace nix