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

Add Color.Equals() override without casting. #502

Merged
merged 6 commits into from
Dec 6, 2022

Conversation

KallDrexx
Copy link
Contributor

Currently, if someone wants to check for color equality they may do color1.Equals(color2). This currently ends up calling the Equals(object other) which requires type checks and casting. This adds significant performance penalty, which adds up in some contexts (e.g. checking each pixel you are drawing isn't the designated transparent color).

This can be worked around by using the == and != overloads, but it's not obvious without looking at the source code that these are overloaded to be better optimized. Therefore, to help with the pit of success I've added an Equals overload that doesn't require casting, and significantly improves performance when called many times.

adrianstevens and others added 6 commits November 22, 2022 20:29
Currently, if someone wants to check for color equality they may do `color1.Equals(color2)`. This currently ends up calling the `Equals(object other)` which requires type checks and casting.  This adds significant performance penalty, which adds up in some contexts (e.g. checking each pixel you are drawing isn't the designated transparent color).

This can be worked around by using the `==` and `!=` overloads, but it's not obvious without looking at the source code that these are overloaded to be better optimized. Therefore, to help with the pit of success I've added an Equals overload that doesn't require casting, and significantly improves performance when called many times.
@adrianstevens adrianstevens changed the base branch from main to develop December 6, 2022 05:26
@adrianstevens
Copy link
Contributor

Thanks @KallDrexx !

@adrianstevens adrianstevens merged commit 90fc31c into WildernessLabs:develop Dec 6, 2022
@KallDrexx KallDrexx deleted the color_equality branch December 8, 2022 01:14
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