|
好吧,发出来,应该已经是VB的极限速度了。
里面还有个for循环如果用汇编做应该还能有提升。
- Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
- Private Declare Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As Long) As Long
- Private Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpProcName As String) As Long
- Private m_bCode(42) As Byte, m_hMod As Long, m_lpFunc As Long
- Friend Sub QuickSort(idxArray() As Long, ByVal nStart As Long, ByVal nEnd As Long)
- If nEnd - nStart <= 1 Then Exit Sub
- If m_lpFunc Then
- CallWindowProc VarPtr(m_bCode(0)), VarPtr(idxArray(nStart)), nEnd - nStart + 1, m_lpFunc, 0
- Exit Sub
- End If
- End Sub
- Private Sub Class_Initialize()
- Dim s As String, m As Long, i As Long
- m_hMod = LoadLibrary("msvcrt.dll")
- m_lpFunc = GetProcAddress(m_hMod, "qsort")
- s = "89E0E800000000830424156A04FF7008" + _
- "FF7004FF500C83C410C21000" + _
- "8B4C24048B4424088B108B0129D0C3"
- m = Len(s) \ 2
- For i = 0 To m - 1
- m_bCode(i) = Val("&H" + Mid(s, i + i + 1, 2))
- Next i
- End Sub
- Private Sub Class_Terminate()
- FreeLibrary m_hMod
- End Sub
复制代码 |
|