Skip to content

Commit

Permalink
Merge pull request #1175 from hzeller/scope-resolve-use-flat-hash-map
Browse files Browse the repository at this point in the history
Use flat_hash_map instead of std::map in ScopeResolver.
  • Loading branch information
hzeller authored Feb 3, 2022
2 parents 0604145 + 5a25a1b commit f8452fe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions verilog/tools/kythe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ cc_library(
"//common/util:auto_pop_stack",
"//common/util:iterator_range",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/container:flat_hash_map",
],
)

Expand Down
5 changes: 0 additions & 5 deletions verilog/tools/kythe/kythe_facts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
namespace verilog {
namespace kythe {

bool Signature::operator==(const Signature& other) const {
return names_.size() == other.names_.size() &&
std::equal(names_.begin(), names_.end(), other.names_.begin());
}

bool Signature::operator<(const Signature& other) const {
return std::lexicographical_compare(names_.begin(), names_.end(),
other.names_.begin(), other.names_.end());
Expand Down
10 changes: 9 additions & 1 deletion verilog/tools/kythe/kythe_facts.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ class Signature {
names_.push_back(std::string(name));
}

bool operator==(const Signature& other) const;
bool operator==(const Signature& other) const {
return names_ == other.names_;
}
bool operator!=(const Signature& other) const { return !(*this == other); }

// TODO(hzeller): remove other uses of std::set, then operator< can go
bool operator<(const Signature& other) const;

// Returns the signature concatenated as a string.
Expand Down Expand Up @@ -67,6 +71,10 @@ class Signature {
// for "x" ==> ["m", "x"]
std::vector<std::string> names_;
};
template <typename H>
H AbslHashValue(H state, const Signature& v) {
return H::combine(std::move(state), v.Names());
}

// Node vector name for kythe facts.
struct VName {
Expand Down
3 changes: 2 additions & 1 deletion verilog/tools/kythe/scope_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <utility>
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "common/util/auto_pop_stack.h"
#include "common/util/iterator_range.h"
Expand Down Expand Up @@ -245,7 +246,7 @@ class ScopeResolver {
// "pkg1": ["my_fun", "my_class"],
// "pkg2": ["my_fun", "my_class"]
// }
std::map<Signature, Scope> scopes_;
absl::flat_hash_map<Signature, Scope> scopes_;

// Pointer to the previous file's discovered scopes (if a previous file
// exists). This is used for definition finding in cross-file referencing.
Expand Down

0 comments on commit f8452fe

Please sign in to comment.