|
data NormalizedFilePath = NormalizedFilePath !NormalizedUri {-# UNPACK #-} !Text |
|
deriving stock (Generic, Eq, Ord) |
|
data NormalizedUri = NormalizedUri !Int !Text |
|
deriving stock (Read, Show, Generic, Eq) |
I was looking at some -ddump-simpl output from ghcide and noticed that (==) for NormalizedFilePath is somewhat unwieldy. In this case we compare two NormalizedFilePaths named a1 and b1:
case a1 of { NormalizedFilePath ww2 ww3 ww4 ww5 ->
case ww2 of { NormalizedUri ww6 ww7 ->
case ww7 of { Text bx4 bx5 bx6 ->
case b1 of { NormalizedFilePath ww8 ww9 ww10 ww11 ->
case ww8 of { NormalizedUri ww12 ww13 ->
case ww13 of { Text bx3 bx7 bx8 ->
case ==# ww6 ww12 of {
__DEFAULT -> (# _| #) @ZeroBitRep @LiftedRep @(# #) @Target (##);
1# ->
case ==# bx6 bx8 of {
__DEFAULT -> (# _| #) @ZeroBitRep @LiftedRep @(# #) @Target (##);
1# ->
case compareByteArrays# bx4 bx5 bx3 bx7 bx6 of {
__DEFAULT ->
(# _| #) @ZeroBitRep @LiftedRep @(# #) @Target (##);
0# ->
case ==# ww5 ww11 of {
__DEFAULT ->
(# _| #) @ZeroBitRep @LiftedRep @(# #) @Target (##);
1# ->
case compareByteArrays# ww3 ww4 ww9 ww10 ww5 of {
__DEFAULT ->
(# _| #) @ZeroBitRep @LiftedRep @(# #) @Target (##);
0# ->
(# |_ #) @ZeroBitRep @LiftedRep @(# #) @Target wild2
The steps are:
- Compare the hashes stored in the
NormalizedUris
- Compare the lengths of the
Text fields inside the NormalizedUris
- Compare the
ByteArrays of the same Text fields
- Compare the lengths of the unpacked
Text fields in the NormalizedFilePaths
- Compare the
ByteArrays of these Text fields
The first step of comparing the hashes is especially useless in the context of a HashMap or HashSet operation: These operations only check for equality after asserting that the hashes are the same!
It also seems that it should be possible to get away with comparing only one of the Text fields, right? IIUC the NormalizedUri is basically internalNormalizedFilePathToUri nfp, where nfp is the NFP Text field.
So how about this?!
NormalizedFilePath _uri1 nfp1 == NormalizedFilePath _uri2 nfp2 = nfp1 == nfp2
lsp/lsp-types/src/Language/LSP/Protocol/Types/Uri.hs
Lines 201 to 202 in 774f0e9
lsp/lsp-types/src/Language/LSP/Protocol/Types/Uri.hs
Lines 56 to 57 in 774f0e9
I was looking at some
-ddump-simploutput fromghcideand noticed that(==)forNormalizedFilePathis somewhat unwieldy. In this case we compare twoNormalizedFilePaths nameda1andb1:The steps are:
NormalizedUrisTextfields inside theNormalizedUrisByteArrays of the sameTextfieldsTextfields in theNormalizedFilePathsByteArrays of theseTextfieldsThe first step of comparing the hashes is especially useless in the context of a
HashMaporHashSetoperation: These operations only check for equality after asserting that the hashes are the same!It also seems that it should be possible to get away with comparing only one of the
Textfields, right? IIUC theNormalizedUriis basicallyinternalNormalizedFilePathToUri nfp, wherenfpis the NFPTextfield.So how about this?!