Skip to content
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

parser/opcode: fix format function for mod opcode #7455

Merged
merged 2 commits into from
Aug 22, 2018

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

Before this fix, format Mod opcode will get %!(NOVERB)

What is changed and how it works?

Use fmt.Printf correctly.

Check List

Tests

  • Unit test

@lysu @jackysp

@lysu
Copy link
Contributor

lysu commented Aug 21, 2018

/run-all-tests

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -134,5 +134,5 @@ var opsLiteral = map[Op]string{

// Format the ExprNode into a Writer.
func (o Op) Format(w io.Writer) {
fmt.Fprintf(w, opsLiteral[o])
fmt.Fprintf(w, "%s", opsLiteral[o])
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe w.Write([]byte(opsLiteral[o])) is better? 0.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

or make opsLiteral be map[Op][]byte then w.write(opsLiteral[o])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is still a memory allocation in w.Write([]byte(opsLiteral[o])) when converting string to []byte.
If you want better performance, the 'hack' could be used, but I don't think it matters here.

@lysu lysu added status/LGT1 Indicates that a PR has LGTM 1. status/all tests passed labels Aug 21, 2018
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/parser status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants