Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

fix sgen if/else issue #25562

Merged
merged 4 commits into from
Dec 5, 2017
Merged

fix sgen if/else issue #25562

merged 4 commits into from
Dec 5, 2017

Conversation

huanwu
Copy link
Contributor

@huanwu huanwu commented Nov 28, 2017

Port the if/else fix from SG to corefx. Fix another if/else issue when write member elements only when the total number of members is bigger than 1000.

Fix #25248

@shmao @zhenlan @mconnew

@huanwu huanwu self-assigned this Nov 28, 2017
@@ -2197,6 +2200,8 @@ private void WriteMemberElementsIf(Member[] members, Member anyElement, string e
Writer.WriteLine("switch (state) {");
}
int cases = 0;
bool largeNumberOfMembers = (members.Length > 1000);
Copy link
Contributor

@shmao shmao Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the number set to 1000?

Besides, I think it'd be better to extract the value into a readonly variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there are perf concerns, I would not bother to generate different code.

@@ -2197,6 +2200,8 @@ private void WriteMemberElementsIf(Member[] members, Member anyElement, string e
Writer.WriteLine("switch (state) {");
}
int cases = 0;
bool largeNumberOfMembers = (members.Length > 1000);
bool useDoWhile = largeNumberOfMembers && !isSequence;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add comments here explaining why we want to use do...while.

@@ -2217,7 +2220,8 @@ private void WriteMemberElementsIf(Member[] members, Member anyElement, string e
ElementAccessor e = elements[j];
string ns = e.Form == XmlSchemaForm.Qualified ? e.Namespace : "";
if (!isSequence && e.Any && (e.Name == null || e.Name.Length == 0)) continue;
if (!firstElement || (!isSequence && count > 0))

if(!firstElement && isSequence)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any case we want to write else. And when would this condition be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes are only for the case when isSequence = false.

@@ -2344,7 +2353,10 @@ private void WriteMemberElementsIf(Member[] members, Member anyElement, string e
if (isSequence)
Writer.WriteLine("default:");
else
Writer.WriteLine("else {");
{
Writer.WriteLine("Finish:");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right place for Finish:? This seems to be the line of original else. I guessed the Finish label should be after the original else block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. So the Finish tag has to put outside of this method. Seems goto is not the right way in this case and I will switch back to do while(false).

}
else
{
Writer.Indent--;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Finish label should probably be here.

@stephentoub
Copy link
Member

@huanwu, @shmao, what's the status of this PR? Is there still work to be done, or can it be squashed and merged?

@huanwu huanwu merged commit c867915 into dotnet:master Dec 5, 2017
shmao pushed a commit to shmao/corefx that referenced this pull request Dec 6, 2017
* Port the if/else fix from SG to corefx. Fix another if/else issue when write member elements only when the total number of members is bigger than 1000

* Use goto instead of do while.

* Use do while.

* Add missing Indent++ when IsSequence=true.
@karelz karelz added this to the 2.1.0 milestone Dec 28, 2017
shmao pushed a commit to shmao/corefx that referenced this pull request Jan 3, 2018
* Port the if/else fix from SG to corefx. Fix another if/else issue when write member elements only when the total number of members is bigger than 1000

* Use goto instead of do while.

* Use do while.

* Add missing Indent++ when IsSequence=true.
huanwu added a commit to huanwu/corefx that referenced this pull request Jan 12, 2018
huanwu added a commit that referenced this pull request Jan 12, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Port the if/else fix from SG to corefx. Fix another if/else issue when write member elements only when the total number of members is bigger than 1000

* Use goto instead of do while.

* Use do while.

* Add missing Indent++ when IsSequence=true.


Commit migrated from dotnet/corefx@c867915
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix the SGEN performance issue
5 participants