refactor(3p/nix/libexpr): Use Abseil collection types for parser state
Replaces the previous uses of the (ordered!) std::map and std::set with absl::flat_hash_{map|set}. After some careful reading it seems that there is actually no ordering dependency on these types, and the (drop-in) replacements perform slightly better. Overall this is not fixing a bottleneck, just a driveby thing. Change-Id: Ided695dc75676bd58515aa9382df0be0a09c565e Reviewed-on: https://cl.tvl.fyi/c/depot/+/1220 Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: isomer <isomer@tvl.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
1b42504a12
commit
d470ec0d29
2 changed files with 13 additions and 2 deletions
10
third_party/nix/src/libexpr/nixexpr.hh
vendored
10
third_party/nix/src/libexpr/nixexpr.hh
vendored
|
@ -3,6 +3,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <absl/container/flat_hash_map.h>
|
||||||
|
|
||||||
#include "libexpr/symbol-table.hh"
|
#include "libexpr/symbol-table.hh"
|
||||||
#include "libexpr/value.hh"
|
#include "libexpr/value.hh"
|
||||||
|
@ -183,6 +184,7 @@ struct ExprOpHasAttr : Expr {
|
||||||
|
|
||||||
struct ExprAttrs : Expr {
|
struct ExprAttrs : Expr {
|
||||||
bool recursive;
|
bool recursive;
|
||||||
|
|
||||||
struct AttrDef {
|
struct AttrDef {
|
||||||
bool inherited;
|
bool inherited;
|
||||||
Expr* e;
|
Expr* e;
|
||||||
|
@ -192,16 +194,20 @@ struct ExprAttrs : Expr {
|
||||||
: inherited(inherited), e(e), pos(pos){};
|
: inherited(inherited), e(e), pos(pos){};
|
||||||
AttrDef(){};
|
AttrDef(){};
|
||||||
};
|
};
|
||||||
typedef std::map<Symbol, AttrDef> AttrDefs;
|
|
||||||
|
typedef absl::flat_hash_map<Symbol, AttrDef> AttrDefs;
|
||||||
AttrDefs attrs;
|
AttrDefs attrs;
|
||||||
|
|
||||||
struct DynamicAttrDef {
|
struct DynamicAttrDef {
|
||||||
Expr *nameExpr, *valueExpr;
|
Expr *nameExpr, *valueExpr;
|
||||||
Pos pos;
|
Pos pos;
|
||||||
DynamicAttrDef(Expr* nameExpr, Expr* valueExpr, const Pos& pos)
|
DynamicAttrDef(Expr* nameExpr, Expr* valueExpr, const Pos& pos)
|
||||||
: nameExpr(nameExpr), valueExpr(valueExpr), pos(pos){};
|
: nameExpr(nameExpr), valueExpr(valueExpr), pos(pos){};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
|
typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
|
||||||
DynamicAttrDefs dynamicAttrs;
|
DynamicAttrDefs dynamicAttrs;
|
||||||
|
|
||||||
ExprAttrs() : recursive(false){};
|
ExprAttrs() : recursive(false){};
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
@ -336,7 +342,7 @@ struct ExprPos : Expr {
|
||||||
struct StaticEnv {
|
struct StaticEnv {
|
||||||
bool isWith;
|
bool isWith;
|
||||||
const StaticEnv* up;
|
const StaticEnv* up;
|
||||||
typedef std::map<Symbol, unsigned int> Vars;
|
typedef absl::flat_hash_map<Symbol, unsigned int> Vars;
|
||||||
Vars vars;
|
Vars vars;
|
||||||
StaticEnv(bool isWith, const StaticEnv* up) : isWith(isWith), up(up){};
|
StaticEnv(bool isWith, const StaticEnv* up) : isWith(isWith), up(up){};
|
||||||
};
|
};
|
||||||
|
|
5
third_party/nix/src/libexpr/symbol-table.hh
vendored
5
third_party/nix/src/libexpr/symbol-table.hh
vendored
|
@ -26,6 +26,11 @@ class Symbol {
|
||||||
bool empty() const { return s->empty(); }
|
bool empty() const { return s->empty(); }
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& str, const Symbol& sym);
|
friend std::ostream& operator<<(std::ostream& str, const Symbol& sym);
|
||||||
|
|
||||||
|
template <typename H>
|
||||||
|
friend H AbslHashValue(H h, const Symbol& c) {
|
||||||
|
return H::combine(std::move(h), c.s);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// SymbolTable is a hash-set based symbol-interning mechanism.
|
// SymbolTable is a hash-set based symbol-interning mechanism.
|
||||||
|
|
Loading…
Reference in a new issue