Re: Fastcode CharPosRev B&V 0.6.2



Hi,

Created my last "idea"

Hope it's faster..

function CharPosRev_DLA_PAS_19_a(SearchChar: Char; const S: string):
Integer;
var
PStart, PWalk: PChar;
StrLength: Integer;
label
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16;
begin
StrLength := Length(S);
if StrLength > 0 then
begin
PStart := Pointer(S);
PWalk := Pointer((Cardinal(S) + Cardinal(StrLength)) - 16);
while PWalk >= PStart do
begin
if PWalk[15] = SearchChar then
begin
Result := (PWalk - PStart) + 16;
Exit;
end;
if PWalk[14] = SearchChar then
begin
Result := (PWalk - PStart) + 15;
Exit;
end;
if PWalk[13] = SearchChar then
begin
Result := (PWalk - PStart) + 14;
Exit;
end;
if PWalk[12] = SearchChar then
begin
Result := (PWalk - PStart) + 13;
Exit;
end;
if PWalk[11] = SearchChar then
begin
Result := (PWalk - PStart) + 12;
Exit;
end;
if PWalk[10] = SearchChar then
begin
Result := (PWalk - PStart) + 11;
Exit;
end;
if PWalk[9] = SearchChar then
begin
Result := (PWalk - PStart) + 10;
Exit;
end;
if PWalk[8] = SearchChar then
begin
Result := (PWalk - PStart) + 9;
Exit;
end;
if PWalk[7] = SearchChar then
begin
Result := (PWalk - PStart) + 8;
Exit;
end;
if PWalk[6] = SearchChar then
begin
Result := (PWalk - PStart) + 7;
Exit;
end;
if PWalk[5] = SearchChar then
begin
Result := (PWalk - PStart) + 6;
Exit;
end;
if PWalk[4] = SearchChar then
begin
Result := (PWalk - PStart) + 5;
Exit;
end;
if PWalk[3] = SearchChar then
begin
Result := (PWalk - PStart) + 4;
Exit;
end;
if PWalk[2] = SearchChar then
begin
Result := (PWalk - PStart) + 3;
Exit;
end;
if PWalk[1] = SearchChar then
begin
Result := (PWalk - PStart) + 2;
Exit;
end;
if PWalk[0] = SearchChar then
begin
Result := (PWalk - PStart) + 1;
Exit;
end;
Dec(PWalk, 16);
end;
case (PStart - PWalk) of
0: goto c16;
1: goto c15;
2: goto c14;
3: goto c13;
4: goto c12;
5: goto c11;
6: goto c10;
7: goto c9;
8: goto c8;
9: goto c7;
10: goto c6;
11: goto c5;
12: goto c4;
13: goto c3;
14: goto c2;
15: goto c1;
16: goto c0;
end;
c16:
if PStart[15] = SearchChar then
begin
Result := 16;
Exit;
end;
c15:
if PStart[14] = SearchChar then
begin
Result := 15;
Exit;
end;
c14:
if PStart[13] = SearchChar then
begin
Result := 14;
Exit;
end;
c13:
if PStart[12] = SearchChar then
begin
Result := 13;
Exit;
end;
c12:
if PStart[11] = SearchChar then
begin
Result := 12;
Exit;
end;
c11:
if PStart[10] = SearchChar then
begin
Result := 11;
Exit;
end;
c10:
if PStart[9] = SearchChar then
begin
Result := 10;
Exit;
end;
c9:
if PStart[8] = SearchChar then
begin
Result := 9;
Exit;
end;
c8:
if PStart[7] = SearchChar then
begin
Result := 8;
Exit;
end;
c7:
if PStart[6] = SearchChar then
begin
Result := 7;
Exit;
end;
c6:
if PStart[5] = SearchChar then
begin
Result := 6;
Exit;
end;
c5:
if PStart[4] = SearchChar then
begin
Result := 5;
Exit;
end;
c4:
if PStart[3] = SearchChar then
begin
Result := 4;
Exit;
end;
c3:
if PStart[2] = SearchChar then
begin
Result := 3;
Exit;
end;
c2:
if PStart[1] = SearchChar then
begin
Result := 2;
Exit;
end;
c1:
if PStart[0] = SearchChar then
begin
Result := 1;
Exit;
end;
end;
c0:
Result := 0;
end;

function CharPosRev_DLA_PAS_20_a(SearchChar: Char; const S: string):
Integer;
var
PStart, PWalk: PChar;
StrLength: Integer;
label
c0, c1, c2, c3, c4, c5, c6, c7, c8;
begin
StrLength := Length(S);
if StrLength > 0 then
begin
PStart := Pointer(S);
PWalk := Pointer((Cardinal(S) + Cardinal(StrLength)) - 8);
while PWalk >= PStart do
begin
if PWalk[7] = SearchChar then
begin
Result := (PWalk - PStart) + 8;
Exit;
end;
if PWalk[6] = SearchChar then
begin
Result := (PWalk - PStart) + 7;
Exit;
end;
if PWalk[5] = SearchChar then
begin
Result := (PWalk - PStart) + 6;
Exit;
end;
if PWalk[4] = SearchChar then
begin
Result := (PWalk - PStart) + 5;
Exit;
end;
if PWalk[3] = SearchChar then
begin
Result := (PWalk - PStart) + 4;
Exit;
end;
if PWalk[2] = SearchChar then
begin
Result := (PWalk - PStart) + 3;
Exit;
end;
if PWalk[1] = SearchChar then
begin
Result := (PWalk - PStart) + 2;
Exit;
end;
if PWalk[0] = SearchChar then
begin
Result := (PWalk - PStart) + 1;
Exit;
end;
Dec(PWalk, 8);
end;
case (PStart - PWalk) of
0: goto c8;
1: goto c7;
2: goto c6;
3: goto c5;
4: goto c4;
5: goto c3;
6: goto c2;
7: goto c1;
8: goto c0;
end;
c8:
if PStart[7] = SearchChar then
begin
Result := 8;
Exit;
end;
c7:
if PStart[6] = SearchChar then
begin
Result := 7;
Exit;
end;
c6:
if PStart[5] = SearchChar then
begin
Result := 6;
Exit;
end;
c5:
if PStart[4] = SearchChar then
begin
Result := 5;
Exit;
end;
c4:
if PStart[3] = SearchChar then
begin
Result := 4;
Exit;
end;
c3:
if PStart[2] = SearchChar then
begin
Result := 3;
Exit;
end;
c2:
if PStart[1] = SearchChar then
begin
Result := 2;
Exit;
end;
c1:
if PStart[0] = SearchChar then
begin
Result := 1;
Exit;
end;
end;
c0:
Result := 0;
end;

Regards,
Davy


.


Quantcast