Improve performance of Equals function in IndexPath #269
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
Improves the performance of the
Equals
function, as well as the==
and!=
operations, by pre-calculating the hash code in the constructor and using it to compare the objects.What is the current behavior?
When two
IndexPath
objects are compared for equality, theCompareTo
method is executed, which can be too slow when comparing a large number ofIndexPaths
The
IndexPaths
comparison is a limitation when trying to expand all nodes in a large tree, because it is a very heavily used operation used to convert model indexes to row indexes.What is the updated/expected behavior with this PR?
In every constructor of the
IndexPath
we calculate the hash code and store it in a member. Then this member is used whenever we need to compare twoIndexPath
objects for equality, which is much faster than using theCompareTo
method.