TStringList.SetCapacity can be found inside stringl.inc.
Procedure TStringList.SetCapacity(NewCapacity: Integer);
Var NewList : Pointer;
MSize : Longint;
begin
If (NewCapacity<0) then
Error (SListCapacityError,NewCapacity);
If NewCapacity>FCapacity then
begin
GetMem (NewList,NewCapacity*SizeOf(TStringItem));
If NewList=Nil then
Error (SListCapacityError,NewCapacity);
If Assigned(FList) then
begin
MSize:=FCapacity*Sizeof(TStringItem);
System.Move (FList^,NewList^,MSize);
FillWord (Pchar(NewList)[MSize],(NewCapacity-FCapacity)*WordRatio, 0);//<--------------
FreeMem (Flist,MSize);
end;
...
I'd like the rationale to be checked. I think somebody tried to optimize the line
FillByte(Pchar(NewList)[MSize],(NewCapacity-FCapacity)*SizeOf(TStringItem),0);
with
FillWord (Pchar(NewList)[MSize],(NewCapacity-FCapacity)*WordRatio, 0);
The above lines don't fill with zeros the same size, the existing line fills only half the space difference. This is because classesh.inc has {$H+}, which makes SizeOf(TStringItem)=2*SizeOf(Pointer), while WordRatio = SizeOf(Pointer) Div SizeOf(Word).
I don't think it's very important but, am I wrong?