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

Bug + Perf: RelativePath.GetHashCode is Case Sensitive #25

Closed
Sewer56 opened this issue Oct 9, 2023 · 1 comment
Closed

Bug + Perf: RelativePath.GetHashCode is Case Sensitive #25

Sewer56 opened this issue Oct 9, 2023 · 1 comment
Assignees
Labels
meta-bug Something isn't working suggested-for-prioritization App developers can mark issues for consideration during Milestone planning.

Comments

@Sewer56
Copy link
Member

Sewer56 commented Oct 9, 2023

Bug Report

Summary

RelativePath.GetHashCode uses a custom vectorised function for calculating the HashCode of a string that I once made for my Virtual FileSystem. This function is case-sensitive (as it hashes the raw bytes), however the current specification suggests that paths should be compared case insensitive.

More precisely, our GetHashCode is case sensitive, while our Equals is case insensitive, which breaks the contract.

Steps to reproduce

Hash two RelativePath(s) with different casing, and note the hash differs.

What is the expected behaviour?

For any two strings which are equal with Equals, their GetHashCode must match too.

Design

Apply the following steps:

  • Create helper method which converts to lower on stack, before hashing. GetNonRandomizedHashCode32Lower
  • Create benchmark for Hashing with string.GetHashCode(OrdinalIgnoreCase) vs GetNonRandomizedHashCode32Lower
  • Compare the performance of the two, pick the faster of the two.
  • Apply the new faster hash function to AbsolutePath too.

Note:

Use TextInfo.ChangeCase<ToUpperConversion> for changing the case. It contains a backported vectorised implementation from .NET 8.
We can switch to regular ToLower Span extension once we start targeting .NET 8. If you want, can use #if !NET7_0_OR_GREATER define to include conditional, so we don't forget to replace it.

Other information

When the Path library was initially rewritten by me, the requirements and implementation were a bit different. Back then we converted RelativePath(s) into lowercase. However, circumstances have changed, and we stopped doing this a while back.

@Sewer56 Sewer56 added the bug label Oct 9, 2023
@Sewer56 Sewer56 added this to MVP Oct 9, 2023
@Sewer56 Sewer56 changed the title Bug: RelativePath.GetHashCode is Case Sensitive Bug + Perf: RelativePath.GetHashCode is Case Sensitive Oct 9, 2023
@Greg-Nexus Greg-Nexus removed the bug label Oct 10, 2023
@Sewer56 Sewer56 added the meta-bug Something isn't working label Oct 10, 2023
@Sewer56 Sewer56 moved this to To Do in MVP Oct 10, 2023
@Sewer56 Sewer56 added the suggested-for-prioritization App developers can mark issues for consideration during Milestone planning. label Nov 13, 2023
@Sewer56
Copy link
Member Author

Sewer56 commented Nov 13, 2023

Suggested for prioritization as for #26 , some tests needed disabling due to this bug.

@Sewer56 Sewer56 moved this from To Do to In Progress in MVP Nov 14, 2023
@Sewer56 Sewer56 self-assigned this Nov 14, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in MVP Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta-bug Something isn't working suggested-for-prioritization App developers can mark issues for consideration during Milestone planning.
Projects
Archived in project
Development

No branches or pull requests

2 participants