Skip to content

Incorrect Asm in x64 FastStringBuilder Append for Char #5

Open

Description

@deadserious

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.

Activity

  1. JBontes commented on Oct 15, 2018

    @JBontes
    Owner

    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;
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions