-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor record ToString improvements #54630
Conversation
I don't know exactly what else must be done to ensure that Append(char) will be successfully referred to
All the headers for each new printable member are merged into one compiled string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'm just fine with a minor improvement to code gen size if someone wants to contribute it and it looks good.
@jcouv, could you take a look?
block.Add(makeAppendString(F, builder, " = ")); | ||
var memberHeader = $"{member.Name} = "; | ||
if (i > 0) | ||
memberHeader = ", " + memberHeader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please use braces to match rest of the code
@@ -87,6 +87,10 @@ static BoundStatement makeAppendString(SyntheticBoundNodeFactory F, BoundLocal b | |||
{ | |||
return F.ExpressionStatement(F.Call(receiver: builder, F.WellKnownMethod(WellKnownMember.System_Text_StringBuilder__AppendString), F.StringLiteral(value))); | |||
} | |||
static BoundStatement makeAppendChar(SyntheticBoundNodeFactory F, BoundLocal builder, char value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: empty line to separate methods would be desirable
@@ -4903,25 +4911,21 @@ public void ToString_TopLevelRecord_OneField_ValueType() | |||
|
|||
v.VerifyIL("C1." + WellKnownMemberNames.PrintMembersMethodName, @" | |||
{ | |||
// Code size 50 (0x32) | |||
// Code size 38 (0x26) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say the reduction in IL size is probably the biggest benefit. I think that's nice. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 6) with some formatting nits. Please let us know if could address, then we'll merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcouv for another look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 7)
Merged/squashed. Thanks @alfasgd for the contribution! |
Closes #54600
This implements all the mentioned improvements
Append(string)
Append(char)
Additionally, also changes some tests to comfort to the new changes to the emitted IL and diagnostics.
Effects
As measured from the diffs of the expected emitted IL tests:
ToString
gets a -6 byte code sizePrintMembers
gets -12 byte code size for 1 member, -36 for 2, expected formula:-12 - 24 * (members - 1)