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

Use 'go generate' in bytesconv.go #663

Merged
merged 3 commits into from
Sep 28, 2019
Merged

Use 'go generate' in bytesconv.go #663

merged 3 commits into from
Sep 28, 2019

Conversation

zhangyunhao116
Copy link
Contributor

@zhangyunhao116 zhangyunhao116 commented Sep 26, 2019

There are lots of tables in bytesconv.go, maybe we could use 'go generate' to generate these tables in a new file, called 'bytesconv_table.go'. In this way we can reduce init-time and also speed up our conversion, since the table is a constant which defined in compile-time.

)

func main() {
var hex2intTable = func() [256]byte {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you change these to := declarations like hex2intTable := .... I prefer those, thanks!

tmp[i] = v[i]
}
fmt.Fprintf(w, table, k, string(tmp))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would just replace the whole above code with:

fmt.Fprintf(w, "const hex2intTable = %q\n", hex2intTable)
fmt.Fprintf(w, "const toLowerTable = %q\n", toLowerTable)
fmt.Fprintf(w, "const toUpperTable = %q\n", toUpperTable)
fmt.Fprintf(w, "const quotedArgShouldEscapeTable = %q\n", quotedArgShouldEscapeTable)
fmt.Fprintf(w, "const quotedPathShouldEscapeTable = %q\n", quotedPathShouldEscapeTable)

bytesconv_table_gen.go Show resolved Hide resolved
if err := ioutil.WriteFile("bytesconv_table.go", out, 0660); err != nil {
log.Fatal(err)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove empty line.


package fasthttp

`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you move this constant to the top of the file, I prefer to have them there. Thanks.

`

const table = `const %s = %#v
`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one can then be removed.

@zhangyunhao116
Copy link
Contributor Author

Thanks for review! all done

@erikdubbelboer erikdubbelboer merged commit b1ca43f into valyala:master Sep 28, 2019
@erikdubbelboer
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants