-
Notifications
You must be signed in to change notification settings - Fork 2.3k
use AppendFormat to format time values #615
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 AppendFormat to format time values #615
Conversation
use AppendFormat to format time values
Have you checked if there actually is a dynamic allocation or if the compiler is smart enough to optimize it away in this case? The tests are currently failing, since |
No need to keep Go 1.4 support. |
https://golang.org/doc/devel/release.html#policy
Current Go is 1.8 and Go 1.7 will get critical security fix. |
We just dropped support for Go 1.3 and earlier with 72e0ac3. Also removing Go 1.4 would be completely fine IMO. |
Actually it would be beneficial to only support Go 1.5+ as we then could start to reorganize our code into internal sub-packages. |
OK, I'll revert the last two commits and edit the travis file to not run on Go 1.4 and below, does that sound good? |
Preferably rebase on the current master head and also edit the README: 72e0ac3#diff-04c6e90faac2675aa89e2176d2eec7d8L42 |
Cool 👍 |
38b74c6
to
bfd41ad
Compare
This should be good to go, let me know if anything else should be changed. |
Thanks for the quick review! |
Thanks for contributing! |
@@ -1078,17 +1078,19 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { | |||
paramTypes[i+i] = fieldTypeString | |||
paramTypes[i+i+1] = 0x00 | |||
|
|||
var val []byte | |||
var a [64]byte | |||
var b = a[:0] |
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.
Sorry for commenting on old piece of code but I came here from an article and I can't help but wonder, why this wasn't done by make([]byte, 0, 64)
. Isn't it the same?
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 think the compiler can optimize “make” to be stack allocated if possible, so the end result is the same whether we use make or declare an array, it’s just a style decision.
The optimization doesn’t come from the use of an array, it comes from writing directly into a pre-allocated buffer instead of working with intermediary heap allocated values.
Description
This pull request changes the method used to format time values from
Format
toAppendFormat
. The intent is to prevent the dynamic memory allocation that occurs when generating the returnedstring
.Checklist