Skip to content

transparently simplify control flow#83

Merged
keegancsmith merged 1 commit intosourcegraph:masterfrom
extemporalgenome:simplify-control-flow
Feb 17, 2025
Merged

transparently simplify control flow#83
keegancsmith merged 1 commit intosourcegraph:masterfrom
extemporalgenome:simplify-control-flow

Conversation

@extemporalgenome
Copy link
Contributor

@extemporalgenome extemporalgenome commented Feb 16, 2025

This is behaviorally transparent: existing tests pass.

This will be easier to review in hide-whitespace mode.

case m.response != nil:
resp := m.response
if resp != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The nested if is unnecessary, since the switch case just proved that the response is non-nil.

Comment on lines -426 to -431
if err := checkType(&msg{
ID: msgs[i].ID,
Method: msgs[i].Method,
Result: msgs[i].Result,
Error: msgs[i].Error,
}); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to construct a new msg literal, since the result is identical to what is already in msgs[i].

Comment on lines -121 to -124
switch name {
case "id", "jsonrpc", "meta", "method", "params":
continue
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Through use of pop (and delete), none of these fields will be present.

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

Thanks!

if err != nil {
break
c.close(err)
return
Copy link
Member

Choose a reason for hiding this comment

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

nice I looked at the old code and have no idea why we structured it that way. Thanks

@keegancsmith keegancsmith merged commit 2cc9417 into sourcegraph:master Feb 17, 2025
1 check passed
@extemporalgenome extemporalgenome deleted the simplify-control-flow branch February 17, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants