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

[Performance] Replaced FindIndex in RecyclePool.TryGetElementCore with For loop #17261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Shynkos
Copy link

@Shynkos Shynkos commented Jun 21, 2024

GitHub Issue (If applicable): closes #15806

PR Type

What kind of change does this PR introduce?

  • Other... Please describe: Performance

What is the current behavior?

In RecyclePool when an iterator is created it uses a FindIndex expression which is inefficient

What is the new behavior?

Replaced FindIndex with a For loop
var iter = elements.FindIndex(elemInfo => elemInfo.Owner == winrtOwner || elemInfo.Owner == null);
with
for (int i = 0; i < elements.Count; i++) { if ((elemInfo.Owner == winrtOwner) || (elemInfo.Owner == null)) { iter=i; break; } }

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@CLAassistant
Copy link

CLAassistant commented Jun 21, 2024

CLA assistant check
All committers have signed the CLA.

Comment on lines +71 to +79
var iter=-1;
for (int i = 0; i < elements.Count; i++)
{
if ((elemInfo.Owner == winrtOwner) || (elemInfo.Owner == null))
{
iter=i;
break;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Could you move this to another method for readability?

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.

4 participants