mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06: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;
|
typedef std::map<std::string, Value *> ValMap;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef std::map<PosIdx, DocComment> DocCommentMap;
|
typedef std::unordered_map<PosIdx, DocComment> DocCommentMap;
|
||||||
|
|
||||||
struct Env
|
struct Env
|
||||||
{
|
{
|
||||||
|
@ -335,7 +335,7 @@ private:
|
||||||
* Associate source positions of certain AST nodes with their preceding doc comment, if they have one.
|
* Associate source positions of certain AST nodes with their preceding doc comment, if they have one.
|
||||||
* Grouped by file.
|
* Grouped by file.
|
||||||
*/
|
*/
|
||||||
std::map<SourcePath, DocCommentMap> positionToDocComment;
|
std::unordered_map<SourcePath, DocCommentMap> positionToDocComment;
|
||||||
|
|
||||||
LookupPath lookupPath;
|
LookupPath lookupPath;
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ struct LexerState
|
||||||
/**
|
/**
|
||||||
* @brief Maps some positions to a DocComment, where the comment is relevant to the location.
|
* @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 & positions;
|
||||||
PosTable::Origin origin;
|
PosTable::Origin origin;
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
typedef std::map<PosIdx, DocComment> DocCommentMap;
|
typedef std::unordered_map<PosIdx, DocComment> DocCommentMap;
|
||||||
|
|
||||||
Expr * parseExprFromBuf(
|
Expr * parseExprFromBuf(
|
||||||
char * text,
|
char * text,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ class PosIdx
|
||||||
{
|
{
|
||||||
friend struct LazyPosAcessors;
|
friend struct LazyPosAcessors;
|
||||||
friend class PosTable;
|
friend class PosTable;
|
||||||
|
friend class std::hash<PosIdx>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
@ -37,8 +39,26 @@ public:
|
||||||
{
|
{
|
||||||
return id == other.id;
|
return id == other.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t hash() const noexcept
|
||||||
|
{
|
||||||
|
return std::hash<uint32_t>{}(id);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline PosIdx noPos = {};
|
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-accessor.hh',
|
||||||
'source-path.hh',
|
'source-path.hh',
|
||||||
'split.hh',
|
'split.hh',
|
||||||
|
'std-hash.hh',
|
||||||
'strings.hh',
|
'strings.hh',
|
||||||
'strings-inline.hh',
|
'strings-inline.hh',
|
||||||
'suggestions.hh',
|
'suggestions.hh',
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
#include "ref.hh"
|
#include "ref.hh"
|
||||||
#include "canon-path.hh"
|
#include "canon-path.hh"
|
||||||
#include "source-accessor.hh"
|
#include "source-accessor.hh"
|
||||||
|
#include "std-hash.hh"
|
||||||
#include <boost/functional/hash.hpp> // for boost::hash_combine
|
|
||||||
|
|
||||||
namespace nix {
|
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;
|
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