-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Simplify verify throw and remove unnecessary usings #6999
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
Conversation
These statements only do anything if the condition is false, but they evaluate their arguments either way. These do nontrivial work when evaluating their arguments, so figure out if we should skip it early. This is specifically tuned to BoolEvaluate (part of evaluating conditions)
Slightly reduce other work done
Rather than checking whether false is false.
| /* helpfully display unexpanded token and expanded result in error message */ | ||
| isLeftNum ? RightChild.GetUnexpandedValue(state) : LeftChild.GetUnexpandedValue(state), | ||
| isLeftNum ? RightChild.GetExpandedValue(state) : LeftChild.GetExpandedValue(state)); | ||
| if ((!isLeftNum && !isLeftVersion) || (!isRightNum && !isRightVersion)) |
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.
💗 simple change yet the code is FAR more readable
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.
Not to mention performant! This prevents us from randomly expanding values when we don't expect to need them.
| else if (actualSolutionFiles.Count > 1) | ||
| { | ||
| InitializationException.VerifyThrow(false, projectDirectory == null ? "AmbiguousProjectError" : "AmbiguousProjectDirectoryError", null, projectDirectory); | ||
| InitializationException.VerifyThrow(false, projectDirectory == null ? "AmbiguousProjectError" : "AmbiguousProjectDirectoryError", null, projectDirectory, false); |
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: Since every other VerifyThrow(false,... was turned into Throw(..., should we make an overload for this?
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.
There kinda already is one:
InitializationException.Throw(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword(projectDirectory == null ? "AmbiguousProjectError" : "AmbiguousProjectDirectoryError", projectDirectory), null);
Do you like that better? I don't really care either way. The VerifyThrow --> Throw change should have virtually no user impact.
This has a little random cleanup plus moving the condition outside VerifyThrow calls if simply calling the method would do a nontrivial amount of work. The fourth commit switches VerifyThrow* to Throw* as appropriate.
I haven't measured the performance impact. The first and fourth commits should have ~0 impact, though technically the fourth commit makes it slightly faster in the failure case (by one branch). The third helps us avoid a couple small allocations. The second lets us avoid a nontrivial amount of work in an extremely common case, so if this has a positive perf impact, I would suspect that commit.
It should be easiest to look at this commit-by-commit.