-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Use 'go generate' in bytesconv.go #663
Conversation
bytesconv_table_gen.go
Outdated
) | ||
|
||
func main() { | ||
var hex2intTable = func() [256]byte { |
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.
Can you change these to :=
declarations like hex2intTable := ...
. I prefer those, thanks!
bytesconv_table_gen.go
Outdated
tmp[i] = v[i] | ||
} | ||
fmt.Fprintf(w, table, k, string(tmp)) | ||
} |
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.
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
Outdated
if err := ioutil.WriteFile("bytesconv_table.go", out, 0660); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
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.
Remove empty line.
|
||
package fasthttp | ||
|
||
` |
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.
Can you move this constant to the top of the file, I prefer to have them there. Thanks.
bytesconv_table_gen.go
Outdated
` | ||
|
||
const table = `const %s = %#v | ||
` |
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.
This one can then be removed.
Thanks for review! all done |
Thanks! |
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.