دالة FastCharPos
#2
وعليكم السلام

طيب ايهما اسرع الدالة التي وضعتها ام التي صنعها Peter Morris في وحدته FastStrings.pas

PHP كود :
//NOTE : FastCharPos and FastCharPosNoCase do not require you to pass the length
// of the string, this was only done in FastPos and FastPosNoCase because
// they are used by FastReplace many times over, thus saving a LENGTH()
// operation each time. I can't see you using these two routines for the
// same purposes so I didn't do that this time !
function FastCharPos(const aSource : string; const C: Char; StartPos : Integer) : Integer;
var
L : Integer;
begin
//If this assert failed, it is because you passed 0 for StartPos, lowest value is 1 !!
Assert(StartPos > 0);

Result := 0;
L := Length(aSource);
if 
L = 0 then exit;
if 
StartPos > L then exit;
Dec(StartPos);
asm
PUSH EDI 
//Preserve this register

mov EDI, aSource //Point EDI at aSource
add EDI, StartPos
mov ECX
, L //Make a note of how many chars to search through
sub ECX, StartPos
mov AL
, C //and which char we want
@Loop:
cmp Al, [EDI] //compare it against the SourceString
jz @Found
inc EDI
dec ECX
jnz 
@Loop
jmp 
@NotFound
@Found:
sub EDI, aSource //EDI has been incremented, so EDI-OrigAdress = Char pos !
inc EDI
mov Result
, EDI
@NotFound:

POP EDI
end
;
end;

function 
FastCharPosNoCase(const aSource : string; C: Char; StartPos : Integer) : Integer;
var
L : Integer;
begin
Result 
:= 0;
L := Length(aSource);
if 
L = 0 then exit;
if 
StartPos > L then exit;
Dec(StartPos);
if 
StartPos < 0 then StartPos := 0;

asm
PUSH EDI 
//Preserve this register
PUSH EBX
mov EDX
, GUpcaseLUT

mov EDI
, aSource //Point EDI at aSource
add EDI, StartPos
mov ECX
, L //Make a note of how many chars to search through
sub ECX, StartPos

xor EBX, EBX
mov BL
, C
mov AL
, [EDX+EBX]
@
Loop:
mov BL, [EDI]
inc EDI
cmp Al
, [EDX+EBX]
jz @Found
dec ECX
jnz 
@Loop
jmp 
@NotFound
@Found:
sub EDI, aSource //EDI has been incremented, so EDI-OrigAdress = Char pos !
mov Result, EDI
@NotFound:

POP EBX
POP EDI
end
;
end; 

وهذا رابط الوحده بشكلها الكامل
http://code.google.com/p/ljbvcltools/sou...svn11&r=11
الرد


الردود في هذا الموضوع
دالة FastCharPos - بواسطة SMP3 - 15-03-2013, 05:19 PM
دالة FastCharPos - بواسطة syscall - 16-03-2013, 02:56 AM
دالة FastCharPos - بواسطة SMP3 - 16-03-2013, 10:11 AM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم