VB Code:
[ uuid(842b47f0-0b27-11da-8cd6-0800200c9a66), version(0.1), helpstring("Win32 API Kernel32.DLL") ] library Win32Stuff { importlib("stdole2.tlb"); [dllname("kernel32")] module kernel32 { [ entry("RtlMoveMemory") ] VOID CopyMemory ([in,out] LONG* lpDestination, [in,out] LONG* lpSource, [in] LONG Length); } }
Compile this using MkTypLib (you may need to set a few path environment variables) remove 'CopyMemory' from your declare list and reference the compiled type library.
I get around 18% performance boost.
.. note the varptr function is used to get the ptr to the first array entry.VB Code:
Public Function Sisic4(ByVal pStr As Long, ByVal pFind As Long, ByVal lenStr As Long, ByVal lenFind As Long) As Long Dim i As Long Dim j As Long Dim Flag As Long CopyMemory VarPtr(BufStr(0)), ByVal pStr, ByVal lenStr CopyMemory VarPtr(BufFind(0)), ByVal pFind, ByVal lenFind i = lenStr - 1 If lenFind = 2 Then Do Until i < lenFind If BufStr(i - 1) = BufFind(0) Then Sisic4 = Sisic4 + 1 End If i = i - 2 Loop Else Do Until i < lenFind Flag = 0 j = lenFind - 1 Do Until j < 0 If Not (BufStr(i - (lenFind - j)) = BufFind(j - 1)) Then Flag = -1 Exit Do End If j = j - 2 Loop If Flag = 0 Then Sisic4 = Sisic4 + 1 End If i = i - 2 Loop End If End Function




Reply With Quote