我正在开发一个简单的病毒扫描程序,我正在寻找以下功能的速度改进:
Public Function FindAInB(ByRef byteArrayA() As Byte, ByRef byteArrayB() As Byte) As Integer
Dim startmatch As Integer = -1
Dim offsetA As Integer = 0
Dim offsetB As Integer = 0
For offsetB = 0 To byteArrayB.Length - 1
If byteArrayA(offsetA) = byteArrayB(offsetB) Then
If startmatch = -1 AndAlso offsetB < byteArrayB.Length - 8 Then
startmatch = offsetB
End If
offsetA += 1
If offsetA = byteArrayA.Length Then
Exit For
End If
Else
offsetA = 0
startmatch = -1
End If
Next
Return startmatch
End Function
我需要它快速,因为它在选定文件的字节中搜索大约 7800 字节的数组。有点难以解释,但上面的代码是否有替代方案或加快速度的方法?
提前致谢!