Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate over the smaller list #78323

Merged
merged 2 commits into from
Oct 28, 2020
Merged

Commits on Oct 24, 2020

  1. Iterate over the smaller list

    If there are two lists of different sizes,
    iterating over the smaller list and then
    looking up in the larger list is cheaper
    than vice versa, because lookups scale
    sublinearly.
    est31 committed Oct 24, 2020
    Configuration menu
    Copy the full SHA
    a21c2eb View commit details
    Browse the repository at this point in the history

Commits on Oct 25, 2020

  1. Precompute the associated items

    The associated_items(def_id) call
    allocates internally.
    Previously, we'd have called it for
    each pair, so we'd have had O(n^2)
    many calls. By precomputing the
    associated items, we avoid
    repeating so many allocations.
    
    The only instance where this precomputation
    would be a regression is if there's only
    one inherent impl block for the type,
    as the inner loop then doesn't run.
    In that instance, we just early return.
    
    Also, use SmallVec to avoid doing an
    allocation at all if the number is small
    (the case for most impl blocks out there).
    est31 committed Oct 25, 2020
    Configuration menu
    Copy the full SHA
    6c9b8ad View commit details
    Browse the repository at this point in the history