Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lsp-types/src/Language/LSP/Protocol/Types/Uri.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,13 @@ This is one of the most performance critical parts of HLS, do not
modify it without profiling.
-}
data NormalizedFilePath = NormalizedFilePath !NormalizedUri {-# UNPACK #-} !Text
deriving stock (Generic, Eq, Ord)
deriving stock (Generic)

instance Eq NormalizedFilePath where
NormalizedFilePath _uri1 fp1 == NormalizedFilePath _uri2 fp2 = fp1 == fp2
Copy link
Member Author

@sjakobi sjakobi Nov 19, 2025

Choose a reason for hiding this comment

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

This should be a bit faster when comparing arbitrary NFPs, but slower for NFPs that are likely to be equal, such as in HashMap operations:

Suggested change
NormalizedFilePath _uri1 fp1 == NormalizedFilePath _uri2 fp2 = fp1 == fp2
NormalizedFilePath (NormalizedUri h1 _) fp1 == NormalizedFilePath (NormalizedUri h2 _) fp2 =
h1 == h2 && fp1 == fp2

Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely needs a comment!

Suggested change
NormalizedFilePath _uri1 fp1 == NormalizedFilePath _uri2 fp2 = fp1 == fp2
-- We assume that filepath normalization does not change across the lifetime of HLS, so that
-- if we have two `NormalizedFilePath`s with the same filepath, they also have the same
-- normalized URI.
NormalizedFilePath _uri1 fp1 == NormalizedFilePath _uri2 fp2 = fp1 == fp2


instance Ord NormalizedFilePath where
compare (NormalizedFilePath _uri1 fp1) (NormalizedFilePath _uri2 fp2) = compare fp1 fp2

instance NFData NormalizedFilePath

Expand Down
Loading