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