FastCode
FastCode copied to clipboard
Incorrect Asm in x64 FastStringBuilder Append for Char
When using x64 compiler...
sb := TStringBuilder.Create; sb.Append('{') sb.Append('items:{}'); sb.Append('}');
sb.ToString does not result in the expected '{items:{}}' but instead $01+'items:{}}'
If you comment out the asm and use the delphi native code, it is correct.
Using Delphi Tokyo, I've added testcases for FastStringBuilder.TStringBuilder and I'm unable to confirm your findings both on x64 and x86. Can you pls download the lastest code, retry, and state which compiler you're using. I have Berlin as well. And with a bit of effort I may be able to test it on the older compilers.
Here's the testcode I used to try and confirm your case:
procedure TTestFastStringBuilder<T>.Setup;
begin
FData:= TStringBuilder.Create;
end;
procedure TTestFastStringBuilder<T>.TearDown;
begin
FData.Free;
end;
procedure TTestFastStringBuilder<T>.HardcodedSandwhich;
var
s: string;
c: char;
norm: string;
begin
s:= 'items:{}';
FData.Append('{');
if TypeInfo(T) = TypeInfo(char) then begin
FData.Append('{');
norm := '{' + '{' + '}';
end else if TypeInfo(T) = TypeInfo(string) then begin
FData.Append(s);
norm := '{' + s + '}';
end;
FData.Append('}');
Assert.IsTrue(FData.ToString = norm,'HardcodedSandwhich failed, expected: '+norm+' got: '+FData.ToString);
end;