tint: Optimization: Pre-allocate the ast -> sem map.

Change-Id: I674fe31786b08153509b470d14844d50cb7c3d9c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96143
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2022-07-18 16:47:32 +00:00 committed by Dawn LUCI CQ
parent 59e640b208
commit b71bcdd45e
2 changed files with 8 additions and 1 deletions

View File

@ -103,6 +103,9 @@ bool Resolver::Resolve() {
return false;
}
// Pre-allocate the ast -> sem map with the total number of AST nodes.
builder_->Sem().Reserve(builder_->ASTNodes().Count());
if (!DependencyGraph::Build(builder_->AST(), builder_->Symbols(), builder_->Diagnostics(),
dependencies_)) {
return false;

View File

@ -35,7 +35,7 @@ class Info {
/// Placeholder type used by Get() to provide a default value for EXPLICIT_SEM
using InferFromAST = std::nullptr_t;
/// Resolves to the return type of the Get() method given the desired sementic
/// Resolves to the return type of the Get() method given the desired semantic
/// type and AST type.
template <typename SEM, typename AST>
using GetResultType =
@ -55,6 +55,10 @@ class Info {
/// @return this Program
Info& operator=(Info&& rhs);
/// Pre-allocates the AST -> semantic node map to fit at least the given number of nodes.
/// @param num_ast_nodes the number of AST nodes to pre-allocate the map for.
void Reserve(size_t num_ast_nodes) { map_.reserve(num_ast_nodes); }
/// Get looks up the semantic information for the AST node `node`.
/// @param ast_node the AST node
/// @returns a pointer to the semantic node if found, otherwise nullptr