Быстрый строковой поиск
Данный поиск работает по алгоритму Boyer–Moore. Unicode не поддерживает. Обгоняет стандартный InStr приблизительно в 10 раз.
Платформы: Windows, Linux
Автор: MichaelW
#INCLUDE "crt.bi" Function InStrZ naked( start As Integer, _ s1 As Zstring Ptr, _ s2 As Zstring Ptr ) As Integer Asm mov ecx, [esp+8] '' get pointer to s1 mov edx, [esp+12] '' get pointer to s2 movzx eax, Byte Ptr [ecx] '' get first char test eax, eax '' test for null string jz 0f '' return zero movzx eax, Byte Ptr [edx] '' get first char test eax, eax '' test for null string jz 0f '' return zero push ecx '' preserve ecx around call ''-------------------------------------------- '' The extra '+4' below is to correct for the '' effect of the 'push ecx' above on ESP. ''-------------------------------------------- Add ecx, [esp+4+4] '' correct for start position dec ecx '' correct for change in base push edx '' push pointer to s2 push ecx '' push corrected pointer to s1 Call StrStr '' call CRT strstr function Add esp, 8 '' remove parameters from stack pop ecx '' recover ecx test eax, eax '' test for substring not found jz 0f '' return zero Sub eax, ecx '' subtract address of s1 data inc eax '' adjust return value to base 1 0: ret 12 '' return and remove parameters from stack End Asm End Function