1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

Merge pull request #11191 from DeterminateSystems/hash-symbol

Use std::unordered_map for ValueMap
This commit is contained in:
Eelco Dolstra 2024-07-29 15:30:37 +02:00 committed by GitHub
commit f9d55b4d51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View file

@ -42,7 +42,7 @@ class JSONSax : nlohmann::json_sax<json> {
auto attrs2 = state.buildBindings(attrs.size()); auto attrs2 = state.buildBindings(attrs.size());
for (auto & i : attrs) for (auto & i : attrs)
attrs2.insert(i.first, i.second); attrs2.insert(i.first, i.second);
parent->value(state).mkAttrs(attrs2.alreadySorted()); parent->value(state).mkAttrs(attrs2);
return std::move(parent); return std::move(parent);
} }
void add() override { v = nullptr; } void add() override { v = nullptr; }

View file

@ -70,6 +70,8 @@ public:
auto operator<=>(const Symbol other) const { return id <=> other.id; } auto operator<=>(const Symbol other) const { return id <=> other.id; }
bool operator==(const Symbol other) const { return id == other.id; } bool operator==(const Symbol other) const { return id == other.id; }
friend class std::hash<Symbol>;
}; };
/** /**
@ -133,3 +135,12 @@ public:
}; };
} }
template<>
struct std::hash<nix::Symbol>
{
std::size_t operator()(const nix::Symbol & s) const noexcept
{
return std::hash<decltype(s.id)>{}(s.id);
}
};

View file

@ -494,11 +494,11 @@ void Value::mkBlackhole()
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
typedef std::vector<Value *, traceable_allocator<Value *>> ValueVector; typedef std::vector<Value *, traceable_allocator<Value *>> ValueVector;
typedef std::map<Symbol, Value *, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, Value *>>> ValueMap; typedef std::unordered_map<Symbol, Value *, std::hash<Symbol>, std::equal_to<Symbol>, traceable_allocator<std::pair<const Symbol, Value *>>> ValueMap;
typedef std::map<Symbol, ValueVector, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, ValueVector>>> ValueVectorMap; typedef std::map<Symbol, ValueVector, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, ValueVector>>> ValueVectorMap;
#else #else
typedef std::vector<Value *> ValueVector; typedef std::vector<Value *> ValueVector;
typedef std::map<Symbol, Value *> ValueMap; typedef std::unordered_map<Symbol, Value *> ValueMap;
typedef std::map<Symbol, ValueVector> ValueVectorMap; typedef std::map<Symbol, ValueVector> ValueVectorMap;
#endif #endif