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

remove redundant dictionary lookups #10279

Merged
merged 3 commits into from
Oct 19, 2024

Conversation

SimonCropp
Copy link
Contributor

No description provided.

@paulushub
Copy link

paulushub commented Oct 18, 2024

From:

if (!mergeTo.ContainsKey(pair.Key))
{
      mergeTo[pair.Key] = pair.Value;
}

To:

mergeTo.TryAdd(pair.Key, pair.Value);

The implementations are different, which is faster?

@yufeih
Copy link
Contributor

yufeih commented Oct 19, 2024

From:

if (!mergeTo.ContainsKey(pair.Key))
{
      mergeTo[pair.Key] = pair.Value;
}

To:

mergeTo.TryAdd(pair.Key, pair.Value);

The implementations are different, which is faster?

TryAdd is faster, it computes hash code once.

@yufeih yufeih merged commit 2c3af50 into dotnet:main Oct 19, 2024
6 checks passed
@SimonCropp SimonCropp deleted the remove-redundant-dictionary-lookups branch October 19, 2024 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants