diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-21T03·53+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-21T04·09+0100 |
commit | 97e85f94e5ee7e6c8340011757a71222b8091cda (patch) | |
tree | eb46a1e2a1b06508a30f7b46aa050bc51b24d2b6 /third_party/nix/src/libexpr/symbol-table.cc | |
parent | 00017ace042d183400be78269e99e2952746cce1 (diff) |
refactor(3p/nix/libexpr): Use absl::node_hash_set in SymbolTable r/794
This replaces the previous use of std::unordered_set with absl::node_hash_set. This type was chosen because the current implementation requires pointer stability. This does not yet touch the 'Attr' struct. As a bonus, the implementation of the SymbolTable struct is now consolidated into a single header/implementation file pair.
Diffstat (limited to 'third_party/nix/src/libexpr/symbol-table.cc')
-rw-r--r-- | third_party/nix/src/libexpr/symbol-table.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/third_party/nix/src/libexpr/symbol-table.cc b/third_party/nix/src/libexpr/symbol-table.cc new file mode 100644 index 000000000000..5b9fb27d59aa --- /dev/null +++ b/third_party/nix/src/libexpr/symbol-table.cc @@ -0,0 +1,24 @@ +#include "symbol-table.hh" + +#include <absl/container/node_hash_set.h> +#include <absl/strings/string_view.h> + +namespace nix { + +Symbol SymbolTable::Create(absl::string_view sym) { + auto it = symbols_.emplace(sym); + const string* ptr = &(*it.first); + return Symbol(ptr); +} + +size_t SymbolTable::Size() const { return symbols_.size(); } + +size_t SymbolTable::TotalSize() const { + size_t n = 0; + for (auto& i : symbols_) { + n += i.size(); + } + return n; +} + +} // namespace nix |