⚡ 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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user