Skip to content

Avoid doing multiple dictionary lookups #3580

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

Merged
merged 1 commit into from
Mar 6, 2019
Merged

Avoid doing multiple dictionary lookups #3580

merged 1 commit into from
Mar 6, 2019

Conversation

Henr1k80
Copy link
Contributor

Dictionary lookup involves get key hash, find bucket for hash and iterate bucket for key, so look the value up once, instead of checking if the key exists and then using the indexer to look up the value.
It also reduces the amount of duplicate hardcoded keys in the code.

Could not find any documentation for running the benchmark, so I haven't checked if it actually makes any difference. Haven't analyzed how often the code is executed.

Some places ContainsKey is used before Remove. That is not needed for Dictionary<>, as it will just return false for key not found, but I am uncertain of the specification for IDictionary<> void Remove, so I left it in place.

Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for the PR @Henr1k80 👍

@russcam
Copy link
Contributor

russcam commented Mar 6, 2019

Thanks @Henr1k80 👍

russcam pushed a commit that referenced this pull request Mar 6, 2019
@russcam
Copy link
Contributor

russcam commented Mar 6, 2019

ported to 5.x: 641df53
ported to master: c159ddf

russcam pushed a commit that referenced this pull request Mar 6, 2019
SukharevAndrey pushed a commit to SukharevAndrey/elasticsearch-net that referenced this pull request Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants