Skip to content

Commit

Permalink
Improved Object hashing for Mac x64
Browse files Browse the repository at this point in the history
For Win x64 the performance is almost identical
  • Loading branch information
cristianbuse committed May 28, 2024
1 parent 89acb5e commit 2be071e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Binary file modified benchmarking/Benchmarking.xlsm
Binary file not shown.
16 changes: 12 additions & 4 deletions src/Dictionary.cls
Original file line number Diff line number Diff line change
Expand Up @@ -534,14 +534,22 @@ Private Function GetIndex(ByRef Key As Variant _
End If
#End If
ElseIf vt = vbObject Or vt = vbDataObject Then
Const oPrime As Long = 2701&
Const oPreMask As Long = &H6FFFFFFF
Const oPrime As LongPtr = 2701&
Static iUnk As stdole.IUnknown 'Dim is slower
'
vt = vbObject 'Replace vbDataObject if needed
Set iUnk = Key
hVal = CLng(ObjPtr(iUnk) And oPreMask) 'Ignores high bits on x64
hVal = (hVal + hVal Mod oPrime) And [_maskHM] Or hmObject
#If Win64 Then
Const oPreMask As LongLong = &H6FFFFFFFFFFFFFFF^
Dim ll As LongLong
ll = ObjPtr(iUnk) And oPreMask
ll = ll + ll \ &H1000^ + ll Mod oPrime
hVal = CLng(ll And [_maskHM]) Or hmObject
#Else
Const oPreMask As Long = &H6FFFFFFF
hVal = ObjPtr(iUnk) And oPreMask
hVal = (hVal + hVal Mod oPrime) And [_maskHM] Or hmObject
#End If
Set iUnk = Nothing 'Must call because of Static but still faster
ElseIf vt > vbLongLong Then
Err.Raise 5, , "Cannot hash an Array or User Defined Type"
Expand Down

0 comments on commit 2be071e

Please sign in to comment.