mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
Merge pull request #11113 from NixOS/doc-comment-unordered-map
Doc comments: use std::unordered_map
This commit is contained in:
commit
621c23bbea
8 changed files with 50 additions and 20 deletions
|
@ -130,7 +130,7 @@ struct Constant
|
|||
typedef std::map<std::string, Value *> ValMap;
|
||||
#endif
|
||||
|
||||
typedef std::map<PosIdx, DocComment> DocCommentMap;
|
||||
typedef std::unordered_map<PosIdx, DocComment> DocCommentMap;
|
||||
|
||||
struct Env
|
||||
{
|
||||
|
@ -335,7 +335,7 @@ private:
|
|||
* Associate source positions of certain AST nodes with their preceding doc comment, if they have one.
|
||||
* Grouped by file.
|
||||
*/
|
||||
std::map<SourcePath, DocCommentMap> positionToDocComment;
|
||||
std::unordered_map<SourcePath, DocCommentMap> positionToDocComment;
|
||||
|
||||
LookupPath lookupPath;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ struct LexerState
|
|||
/**
|
||||
* @brief Maps some positions to a DocComment, where the comment is relevant to the location.
|
||||
*/
|
||||
std::map<PosIdx, DocComment> & positionToDocComment;
|
||||
std::unordered_map<PosIdx, DocComment> & positionToDocComment;
|
||||
|
||||
PosTable & positions;
|
||||
PosTable::Origin origin;
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
typedef std::map<PosIdx, DocComment> DocCommentMap;
|
||||
typedef std::unordered_map<PosIdx, DocComment> DocCommentMap;
|
||||
|
||||
Expr * parseExprFromBuf(
|
||||
char * text,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -8,6 +9,7 @@ class PosIdx
|
|||
{
|
||||
friend struct LazyPosAcessors;
|
||||
friend class PosTable;
|
||||
friend class std::hash<PosIdx>;
|
||||
|
||||
private:
|
||||
uint32_t id;
|
||||
|
@ -37,8 +39,26 @@ public:
|
|||
{
|
||||
return id == other.id;
|
||||
}
|
||||
|
||||
size_t hash() const noexcept
|
||||
{
|
||||
return std::hash<uint32_t>{}(id);
|
||||
}
|
||||
};
|
||||
|
||||
inline PosIdx noPos = {};
|
||||
|
||||
}
|
||||
|
||||
namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<nix::PosIdx>
|
||||
{
|
||||
std::size_t operator()(nix::PosIdx pos) const noexcept
|
||||
{
|
||||
return pos.hash();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
|
|
@ -216,6 +216,7 @@ headers = [config_h] + files(
|
|||
'source-accessor.hh',
|
||||
'source-path.hh',
|
||||
'split.hh',
|
||||
'std-hash.hh',
|
||||
'strings.hh',
|
||||
'strings-inline.hh',
|
||||
'suggestions.hh',
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
#include "ref.hh"
|
||||
#include "canon-path.hh"
|
||||
#include "source-accessor.hh"
|
||||
|
||||
#include <boost/functional/hash.hpp> // for boost::hash_combine
|
||||
#include "std-hash.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
24
src/libutil/std-hash.hh
Normal file
24
src/libutil/std-hash.hh
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
//!@file Hashing utilities for use with unordered_map, etc. (ie low level implementation logic, not domain logic like
|
||||
//! Nix hashing)
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace nix {
|
||||
|
||||
/**
|
||||
* hash_combine() from Boost. Hash several hashable values together
|
||||
* into a single hash.
|
||||
*/
|
||||
inline void hash_combine(std::size_t & seed) {}
|
||||
|
||||
template<typename T, typename... Rest>
|
||||
inline void hash_combine(std::size_t & seed, const T & v, Rest... rest)
|
||||
{
|
||||
std::hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
hash_combine(seed, rest...);
|
||||
}
|
||||
|
||||
} // namespace nix
|
|
@ -375,18 +375,4 @@ inline std::string operator + (std::string_view s1, const char * s2)
|
|||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* hash_combine() from Boost. Hash several hashable values together
|
||||
* into a single hash.
|
||||
*/
|
||||
inline void hash_combine(std::size_t & seed) { }
|
||||
|
||||
template <typename T, typename... Rest>
|
||||
inline void hash_combine(std::size_t & seed, const T & v, Rest... rest)
|
||||
{
|
||||
std::hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
|
||||
hash_combine(seed, rest...);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue