Allocate the maximum in 1 go for marshaling

This commit is contained in:
zeroZshadow 2016-06-11 04:20:04 +02:00
parent bb0fb2c0f5
commit 8abf09e1ce

View File

@ -127,7 +127,7 @@ func (f ID) Step() int64 {
// MarshalJSON returns a json byte array string of the snowflake ID. // MarshalJSON returns a json byte array string of the snowflake ID.
func (f ID) MarshalJSON() ([]byte, error) { func (f ID) MarshalJSON() ([]byte, error) {
buff := make([]byte, 0, 2) buff := make([]byte, 0, 22)
buff = append(buff, '"') buff = append(buff, '"')
buff = strconv.AppendInt(buff, int64(f), 10) buff = strconv.AppendInt(buff, int64(f), 10)
buff = append(buff, '"') buff = append(buff, '"')