Kevan Hashemi wrote:
I get a factor of 30 decrease in execution time while making a string out of 10,000 integers when using the following routine to append to append each new interger string to the existing string.
procedure string_append(var s,p:string);
var i,num_to_add,old_length:integer;
begin old_length:=length(s); if (s.capacity-old_length<length(p)) then begin num_to_add:=s.capacity-old_length; setlength(s,s.capacity); end else begin num_to_add:=length(p); setlength(s,old_length+length(p)); end; for i:=1 to num_to_add do s[old_length+i]:=p[i]; end;
So, SetLength is all I needed.
Or simply (this routine is also defined in stringutils.pas which comes which GPC):
procedure AppendStr (var s: String; const Source: String); begin Insert (Source, s, Length (s) + 1) end;
Frank