⚡ Pad fixed-length strings in one step

WriteStringFixed grew the string one character at a time, which is
quadratic in the target length.
This commit is contained in:
2026-11-15 22:06:50 +01:00
parent 585fd92611
commit a25c8296de
+7 -3
View File
@@ -268,10 +268,14 @@ end;
procedure TEnhancedMemoryStream.WriteStringFixed(AValue: string;
ALength: Integer);
var
i: Integer;
oldLength: Integer;
begin
for i := Length(AValue) to ALength do
AValue := AValue + #0;
oldLength := Length(AValue);
if oldLength < ALength then
begin
SetLength(AValue, ALength);
FillChar((PChar(AValue) + oldLength)^, ALength - oldLength, 0);
end;
Write(PChar(AValue)^, ALength);
end;