我把它改成这样了,原来的程序'[' 和 '{'是分不清的,试试看就知道了,
因为它的小写字母转大写字母有bug,并非使用正常的方法转换,虽然我十分
佩服这个小函数,但是问题是需要写清楚的.另外,我把它整个改成汇编子程
序了,这样也许速度可以得到进一步优化.
凡有"//Add by SunLujiang "字样的就是我加上的内容,而
"//Remove by SunLujiang"字样的则是我去掉的部分,希望高手们不要骂
我瞎改才好.
//This routine is an identical copy of FastPOS except where commented! The ide
//a is that when grabbing bytes, it ANDs them with $df, effectively making the
//m lowercase before comparing. Maybe this would be quicker if aFindString was
// made lowercase in one fell swoop at the beginning of the function, saving a
//n AND instruction each time.
function FastPosNoCase(
const aSourceString, aFindString : String;
const aSourceLen, aFindLen, StartPos : integer
) : integer;Pascal
// Remove by SunLujiang
{var
SourceLen : integer;
begin
SourceLen := aSourceLen;
SourceLen := SourceLen - aFindLen;
if (StartPos-1) > SourceLen then begin
Result := 0;
Exit;
end;
SourceLen := SourceLen - StartPos;
SourceLen := SourceLen +2;}
// Remove end
asm
push ESI
push EDI
push EBX
// Add by SunLujiang
Mov ECX, aSourceLen
Mov EAX, aFindLen
Sub ECX, EAX
Jo @Result0
Mov EAX, StartPos
Dec EAX
Sub ECX, EAX
Jo @Result0
Inc ECX
Inc ECX
// Add end
mov EDI, aSourceString
add EDI, StartPos
Dec EDI
mov ESI, aFindString
// Remove by SunLujiang
// mov ECX, SourceLen
// Remove end
Mov Al, [ESI]
// Add by SunLujiang
Cmp Al,97
Jb @NotLowerCase1
Cmp Al,122
Jnb @NotLowerCase1
// Add end
// Make Al lowercase.
and Al, $df
// Add by SunLujiang
@NotLowerCase1:
// Add end
@ScaSB:
Mov Ah, [EDI]
// Add by SunLujiang
Cmp Ah,97
Jb @NotLowerCase2
Cmp Ah,122
Jnb @NotLowerCase2
// Add end
// Make Ah lowercase.
and Ah, $df
// Add by SunLujiang
@NotLowerCase2:
// Add end
cmp Ah,Al
jne @NextChar
@CompareStrings:
mov EBX, aFindLen
dec EBX
//add by ShengQuanhu
Jz @EndOfMatch
//add end
@CompareNext:
mov Al, [ESI+EBX]
mov Ah, [EDI+EBX]
// Add by SunLujiang
Cmp Al,97
Jb @NotLowerCase3
Cmp Al,122
Jnb @NotLowerCase3
// Add end
// Make Al and Ah lowercase.
and Al, $df
// Add by SunLujiang
@NotLowerCase3:
Cmp Ah,97
Jb @NotLowerCase4
Cmp Ah,122
Jnb @NotLowerCase4
// Add end
and Ah, $df
// Add by SunLujiang
@NotLowerCase4:
// Add end
cmp Al, Ah
Jz @Matches
Mov Al, [ESI]
// Make Al lowercase.
and Al, $df
Jmp @NextChar
@Matches:
Dec EBX
Jnz @CompareNext
//add by Shengquanhu
@EndOfMatch:
//add end
mov EAX, EDI
sub EAX, aSourceString
inc EAX
mov Result, EAX
jmp @TheEnd
@NextChar:
Inc EDI
dec ECX
jnz @ScaSB
//add by SunLujiang
@Result0:
//add end
mov Result,0
@TheEnd:
pop EBX
pop EDI
pop ESI
// Remove by SunLujiang
// end;
// Remove end
end;