From d470ec0d2946d77b0e4c4b9a0a1e383c0a817167 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 16 Jul 2020 22:00:26 +0100 Subject: 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 Reviewed-by: isomer Tested-by: BuildkiteCI --- third_party/nix/src/libexpr/nixexpr.hh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'third_party/nix/src/libexpr/nixexpr.hh') diff --git a/third_party/nix/src/libexpr/nixexpr.hh b/third_party/nix/src/libexpr/nixexpr.hh index 3bf9e4a1a77a..4b2bd86ef966 100644 --- a/third_party/nix/src/libexpr/nixexpr.hh +++ b/third_party/nix/src/libexpr/nixexpr.hh @@ -3,6 +3,7 @@ #include #include #include +#include #include "libexpr/symbol-table.hh" #include "libexpr/value.hh" @@ -183,6 +184,7 @@ struct ExprOpHasAttr : Expr { struct ExprAttrs : Expr { bool recursive; + struct AttrDef { bool inherited; Expr* e; @@ -192,16 +194,20 @@ struct ExprAttrs : Expr { : inherited(inherited), e(e), pos(pos){}; AttrDef(){}; }; - typedef std::map AttrDefs; + + typedef absl::flat_hash_map AttrDefs; AttrDefs attrs; + struct DynamicAttrDef { Expr *nameExpr, *valueExpr; Pos pos; DynamicAttrDef(Expr* nameExpr, Expr* valueExpr, const Pos& pos) : nameExpr(nameExpr), valueExpr(valueExpr), pos(pos){}; }; + typedef std::vector DynamicAttrDefs; DynamicAttrDefs dynamicAttrs; + ExprAttrs() : recursive(false){}; COMMON_METHODS }; @@ -336,7 +342,7 @@ struct ExprPos : Expr { struct StaticEnv { bool isWith; const StaticEnv* up; - typedef std::map Vars; + typedef absl::flat_hash_map Vars; Vars vars; StaticEnv(bool isWith, const StaticEnv* up) : isWith(isWith), up(up){}; }; -- cgit 1.4.1