* optimize write loop in int_str

git-svn-id: trunk@9794 -
This commit is contained in:
peter 2008-01-19 16:48:12 +00:00
parent f70219cdd8
commit 1561d97465

View File

@ -1533,39 +1533,40 @@ function align(addr : Pointer;alignment : PtrUInt) : Pointer;{$ifdef SYSTEMINLIN
procedure int_str(l:longint;out s:string); procedure int_str(l:longint;out s:string);
var var
m,m1 : longword; m,m1 : longword;
pcstart,
pc2start,
pc,pc2 : pchar; pc,pc2 : pchar;
hs : string[32]; hs : string[32];
b : longint; overflow : longint;
begin begin
pc2:=@s[1]; pc2start:=@s[1];
pc2:=pc2start;
if (l<0) then if (l<0) then
begin begin
b:=1;
pc2^:='-'; pc2^:='-';
inc(pc2); inc(pc2);
m:=longword(-l); m:=longword(-l);
end end
else else
begin m:=longword(l);
b:=0; pcstart:=pchar(@hs[0]);
m:=longword(l); pc:=pcstart;
end;
pc:=@hs[0];
repeat repeat
inc(pc);
m1:=m div 10; m1:=m div 10;
inc(pc);
pc^:=char(m-(m1*10)+byte('0')); pc^:=char(m-(m1*10)+byte('0'));
m:=m1; m:=m1;
until m=0; until m=0;
while (pc>pchar(@hs[0])) and overflow:=(pc-pcstart)+(pc2-pc2start)-high(s);
(b<high(s)) do if overflow>0 then
inc(pcstart,overflow);
while (pc>pcstart) do
begin begin
pc2^:=pc^; pc2^:=pc^;
dec(pc);
inc(pc2); inc(pc2);
inc(b); dec(pc);
end; end;
s[0]:=chr(b); s[0]:=char(pc2-pc2start);
end; end;
{$endif ndef FPC_SYSTEM_HAS_INT_STR_LONGINT} {$endif ndef FPC_SYSTEM_HAS_INT_STR_LONGINT}
@ -1575,28 +1576,32 @@ end;
procedure int_str(l:longword;out s:string); procedure int_str(l:longword;out s:string);
var var
m1 : longword; m1 : longword;
b: longint; pcstart,
pc2start,
pc,pc2 : pchar; pc,pc2 : pchar;
hs : string[32]; hs : string[32];
overflow : longint;
begin begin
pc2:=@s[1]; pc2start:=@s[1];
pc:=@hs[0]; pc2:=pc2start;
pcstart:=pchar(@hs[0]);
pc:=pcstart;
repeat repeat
inc(pc); inc(pc);
m1:=l div 10; m1:=l div 10;
pc^:=char(l-(m1*10)+byte('0')); pc^:=char(l-(m1*10)+byte('0'));
l:=m1; l:=m1;
until l=0; until l=0;
b:=0; overflow:=(pc-pcstart)-high(s);
while (pc>pchar(@hs[0])) and if overflow>0 then
(b<high(s)) do inc(pcstart,overflow);
while (pc>pcstart) do
begin begin
pc2^:=pc^; pc2^:=pc^;
dec(pc);
inc(pc2); inc(pc2);
inc(b); dec(pc);
end; end;
s[0]:=chr(b); s[0]:=char(pc2-pc2start);
end; end;
{$endif ndef FPC_SYSTEM_HAS_INT_STR_LONGWORD} {$endif ndef FPC_SYSTEM_HAS_INT_STR_LONGWORD}
@ -1606,39 +1611,40 @@ end;
procedure int_str(l:int64;out s:string); procedure int_str(l:int64;out s:string);
var var
m,m1 : qword; m,m1 : qword;
pcstart,
pc2start,
pc,pc2 : pchar; pc,pc2 : pchar;
b: longint; hs : string[32];
hs : string[64]; overflow : longint;
begin begin
pc2:=@s[1]; pc2start:=@s[1];
pc2:=pc2start;
if (l<0) then if (l<0) then
begin begin
b:=1;
pc2^:='-'; pc2^:='-';
inc(pc2); inc(pc2);
m:=qword(-l); m:=qword(-l);
end end
else else
begin m:=qword(l);
b:=0; pcstart:=pchar(@hs[0]);
m:=qword(l); pc:=pcstart;
end;
pc:=@hs[0];
repeat repeat
inc(pc);
m1:=m div 10; m1:=m div 10;
inc(pc);
pc^:=char(m-(m1*10)+byte('0')); pc^:=char(m-(m1*10)+byte('0'));
m:=m1; m:=m1;
until m=0; until m=0;
while (pc>pchar(@hs[0])) and overflow:=(pc-pcstart)+(pc2-pc2start)-high(s);
(b < high(s)) do if overflow>0 then
inc(pcstart,overflow);
while (pc>pcstart) do
begin begin
pc2^:=pc^; pc2^:=pc^;
dec(pc);
inc(pc2); inc(pc2);
inc(b); dec(pc);
end; end;
s[0]:=chr(b); s[0]:=char(pc2-pc2start);
end; end;
{$endif ndef FPC_SYSTEM_HAS_INT_STR_INT64} {$endif ndef FPC_SYSTEM_HAS_INT_STR_INT64}
@ -1648,28 +1654,32 @@ end;
procedure int_str(l:qword;out s:string); procedure int_str(l:qword;out s:string);
var var
m1 : qword; m1 : qword;
pcstart,
pc2start,
pc,pc2 : pchar; pc,pc2 : pchar;
b: longint;
hs : string[64]; hs : string[64];
overflow : longint;
begin begin
pc2:=@s[1]; pc2start:=@s[1];
pc:=@hs[0]; pc2:=pc2start;
pcstart:=pchar(@hs[0]);
pc:=pcstart;
repeat repeat
inc(pc); inc(pc);
m1:=l div 10; m1:=l div 10;
pc^:=char(l-(m1*10)+byte('0')); pc^:=char(l-(m1*10)+byte('0'));
l:=m1; l:=m1;
until l=0; until l=0;
b:=0; overflow:=(pc-pcstart)-high(s);
while (pc>pchar(@hs[0])) and if overflow>0 then
(b<high(s)) do inc(pcstart,overflow);
while (pc>pcstart) do
begin begin
pc2^:=pc^; pc2^:=pc^;
dec(pc);
inc(pc2); inc(pc2);
inc(b); dec(pc);
end; end;
s[0]:=chr(b); s[0]:=char(pc2-pc2start);
end; end;
{$endif ndef FPC_SYSTEM_HAS_INT_STR_QWORD} {$endif ndef FPC_SYSTEM_HAS_INT_STR_QWORD}