⚡ 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; procedure TEnhancedMemoryStream.WriteStringFixed(AValue: string;
ALength: Integer); ALength: Integer);
var var
i: Integer; oldLength: Integer;
begin begin
for i := Length(AValue) to ALength do oldLength := Length(AValue);
AValue := AValue + #0; if oldLength < ALength then
begin
SetLength(AValue, ALength);
FillChar((PChar(AValue) + oldLength)^, ALength - oldLength, 0);
end;
Write(PChar(AValue)^, ALength); Write(PChar(AValue)^, ALength);
end; end;