Skip to content

Commit

Permalink
Use more compact storage for impl lookup buckets. (#4351)
Browse files Browse the repository at this point in the history
If the bucket is of size zero or one, which is expected to be the common
case, then store it directly. For the remaining cases, use a side table
of lookup buckets.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
  • Loading branch information
zygoloid and jonmeow authored Sep 29, 2024
1 parent 5ab957d commit 9d5ec52
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 83 deletions.
6 changes: 3 additions & 3 deletions toolchain/check/handle_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
{.self_id = self_type_id, .constraint_id = constraint_type_id}};

// Add the impl declaration.
auto& lookup_bucket = context.impls().GetOrAddLookupBucket(
auto lookup_bucket_ref = context.impls().GetOrAddLookupBucket(
impl_info.self_id, impl_info.constraint_id);
for (auto prev_impl_id : lookup_bucket) {
for (auto prev_impl_id : lookup_bucket_ref) {
if (MergeImplRedecl(context, impl_info, prev_impl_id)) {
impl_decl.impl_id = prev_impl_id;
break;
Expand All @@ -292,7 +292,7 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
if (!impl_decl.impl_id.is_valid()) {
impl_info.generic_id = FinishGenericDecl(context, impl_decl_id);
impl_decl.impl_id = context.impls().Add(impl_info);
lookup_bucket.push_back(impl_decl.impl_id);
lookup_bucket_ref.push_back(impl_decl.impl_id);
} else {
FinishGenericRedecl(context, impl_decl_id,
context.impls().Get(impl_decl.impl_id).generic_id);
Expand Down
Loading

0 comments on commit 9d5ec52

Please sign in to comment.