From 5b58991a71d15123c010bbbd7f08530dbc31173f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 19 Sep 2014 16:49:41 +0200 Subject: Store Attrs inside Bindings This prevents a double allocation per attribute set. --- src/libexpr/eval.hh | 72 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 24 deletions(-) (limited to 'src/libexpr/eval.hh') diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index af9452c753..3ac40ed34e 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -16,23 +16,59 @@ namespace nix { class EvalState; -struct Attr; -/* Sets are represented as a vector of attributes, sorted by symbol - (i.e. pointer to the attribute name in the symbol table). */ -#if HAVE_BOEHMGC -typedef std::vector > BindingsBase; -#else -typedef std::vector BindingsBase; -#endif +struct Attr +{ + Symbol name; + Value * value; + Pos * pos; + Attr(Symbol name, Value * value, Pos * pos = &noPos) + : name(name), value(value), pos(pos) { }; + Attr() : pos(&noPos) { }; + bool operator < (const Attr & a) const + { + return name < a.name; + } +}; -class Bindings : public BindingsBase +class Bindings { public: + typedef uint32_t size_t; + +private: + size_t size_, capacity; + Attr attrs[0]; + + Bindings(uint32_t capacity) : size_(0), capacity(capacity) { } + +public: + size_t size() { return size_; } + + bool empty() { return !size_; } + + typedef Attr * iterator; + + void push_back(const Attr & attr) + { + assert(size_ < capacity); + attrs[size_++] = attr; + } + iterator find(const Symbol & name); + iterator begin() { return &attrs[0]; } + iterator end() { return &attrs[size_]; } + + Attr & operator[](size_t pos) + { + return attrs[pos]; + } + void sort(); + + friend class EvalState; }; @@ -58,21 +94,6 @@ struct Env }; -struct Attr -{ - Symbol name; - Value * value; - Pos * pos; - Attr(Symbol name, Value * value, Pos * pos = &noPos) - : name(name), value(value), pos(pos) { }; - Attr() : pos(&noPos) { }; - bool operator < (const Attr & a) const - { - return name < a.name; - } -}; - - void mkString(Value & v, const string & s, const PathSet & context = PathSet()); void copyContext(const Value & v, PathSet & context); @@ -245,6 +266,8 @@ public: Value * allocAttr(Value & vAttrs, const Symbol & name); + Bindings * allocBindings(Bindings::size_t capacity); + void mkList(Value & v, unsigned int length); void mkAttrs(Value & v, unsigned int expected); void mkThunk_(Value & v, Expr * expr); @@ -264,6 +287,7 @@ private: unsigned long nrValues; unsigned long nrListElems; unsigned long nrAttrsets; + unsigned long nrAttrsInAttrsets; unsigned long nrOpUpdates; unsigned long nrOpUpdateValuesCopied; unsigned long nrListConcats; -- cgit 1.4.1