mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-29 16:40:25 +02:00
tai_string: remove useless #0 terminators
The string data in the array alrady includes any necessary #0 terminators and the length of the array contains the length of the data, so there is no need to add an additional #0 terminator
This commit is contained in:
parent
547fa426c7
commit
754c40cdb0
@ -736,23 +736,19 @@ implementation
|
||||
case othertai.typ of
|
||||
ait_string:
|
||||
begin
|
||||
// lengths without terminating 0
|
||||
len1:=strtai.len;
|
||||
len2:=lother_string.len;
|
||||
lent:=len1+len2;
|
||||
SetLength(strtai.str,lent+1);
|
||||
{ also copy null terminator }
|
||||
move(lother_string.str[0],strtai.str[len1],len2+1);
|
||||
SetLength(strtai.str,lent);
|
||||
move(lother_string.str[0],strtai.str[len1],len2);
|
||||
end;
|
||||
ait_const:
|
||||
begin
|
||||
if tai_const(othertai).size<>1 then
|
||||
internalerror(2014070101);
|
||||
{ it was already len+1 to hold the #0 -> realloc to len+2 }
|
||||
len1:=length(strtai.str);
|
||||
SetLength(strtai.str,len1+1);
|
||||
strtai.str[len1-1]:=ansichar(tai_const(othertai).value);
|
||||
strtai.str[len1]:=#0;
|
||||
strtai.str[len1]:=ansichar(tai_const(othertai).value);
|
||||
end;
|
||||
else
|
||||
internalerror(2014070102);
|
||||
|
@ -2428,10 +2428,9 @@ implementation
|
||||
inherited Create;
|
||||
typ:=ait_string;
|
||||
lNewLen:=length(_str);
|
||||
setlength(str,lNewLen+1);
|
||||
setlength(str,lNewLen);
|
||||
if lNewLen>0 then
|
||||
move(_str[1],str[0],lNewLen);
|
||||
str[lNewLen]:=#0;
|
||||
end;
|
||||
|
||||
|
||||
@ -2442,10 +2441,9 @@ implementation
|
||||
inherited Create;
|
||||
typ:=ait_string;
|
||||
lNewLen:=length(_str);
|
||||
setlength(str,lNewlen+1);
|
||||
setlength(str,lNewlen);
|
||||
if lNewLen>0 then
|
||||
move(_str[1],str[0],lNewLen);
|
||||
str[lNewLen]:=#0;
|
||||
end;
|
||||
|
||||
|
||||
@ -2453,15 +2451,11 @@ implementation
|
||||
begin
|
||||
inherited Create;
|
||||
typ:=ait_string;
|
||||
setlength(str,length+ord(add0)+1);
|
||||
setlength(str,length+ord(add0));
|
||||
if length>0 then
|
||||
move(data^,str[0],length);
|
||||
if add0 then
|
||||
begin
|
||||
str[length]:=#0;
|
||||
inc(length);
|
||||
end;
|
||||
str[length]:=#0;
|
||||
str[length]:=#0;
|
||||
end;
|
||||
|
||||
|
||||
@ -2477,9 +2471,8 @@ implementation
|
||||
begin
|
||||
inherited ppuload(t,ppufile);
|
||||
lNewLen:=ppufile.getlongint;
|
||||
setlength(str,lNewLen+1);
|
||||
setlength(str,lNewLen);
|
||||
ppufile.getdata(str[0],lnewlen);
|
||||
str[lNewLen]:=#0;
|
||||
end;
|
||||
|
||||
|
||||
@ -2488,7 +2481,7 @@ implementation
|
||||
lWriteLen : integer;
|
||||
begin
|
||||
inherited ppuwrite(ppufile);
|
||||
lWriteLen:=length(str)-1;
|
||||
lWriteLen:=length(str);
|
||||
ppufile.putlongint(lWriteLen);
|
||||
ppufile.putdata(str[0],lWriteLen);
|
||||
end;
|
||||
@ -2502,7 +2495,6 @@ implementation
|
||||
p:=inherited getcopy;
|
||||
lWriteLen:=length(str);
|
||||
setlength(tai_string(p).str,lWriteLen);
|
||||
// move #0 at the end too.
|
||||
move(str[0],tai_string(p).str[0],lWriteLen);
|
||||
getcopy:=p;
|
||||
end;
|
||||
@ -2510,8 +2502,6 @@ implementation
|
||||
function tai_string.len: integer;
|
||||
begin
|
||||
Result:=Length(str);
|
||||
if Result>0 then
|
||||
Result:=Result-1;
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user