Skip to content

Refactor TestAssert: Replace ToArray()[0] with First() for efficiency.#4888

Merged
stevenaw merged 1 commit into
nunit:mainfrom
Saurav-shres:use-first-instead-of-toarray
Nov 23, 2024
Merged

Refactor TestAssert: Replace ToArray()[0] with First() for efficiency.#4888
stevenaw merged 1 commit into
nunit:mainfrom
Saurav-shres:use-first-instead-of-toarray

Conversation

@Saurav-shres
Copy link
Copy Markdown
Contributor

@Saurav-shres Saurav-shres commented Nov 23, 2024

This pull request refactors the TestAssert class, specifically the IsRunnable(Type type, string name, ResultState resultState) method. The change replaces the use of ToArray()[0] with the more efficient First() method from LINQ. This improves the performance by eliminating unnecessary array allocation and directly accessing the first element in the collection.

Fixes #4886

@Saurav-shres
Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

Copy link
Copy Markdown
Member

@stevenaw stevenaw left a comment

Choose a reason for hiding this comment

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

Looks great to me, and all the tests are passing. Thanks for spotting this and for your contribution to fixing it @Saurav-shres

@stevenaw stevenaw merged commit 6e14a0f into nunit:main Nov 23, 2024
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.

Optimize ToArray()[0] with First() in TestAssert class in TestAssert.cs

2 participants