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

cbor: use fmtTime instead of time.Format for RFC3339Nano #394

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion codec/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ func (e *cborEncDriver) EncodeTime(t time.Time) {
e.EncodeNil()
} else if e.h.TimeRFC3339 {
e.encUint(0, cborBaseTag)
e.encStringBytesS(cborBaseString, t.Format(time.RFC3339Nano))
const fmt = time.RFC3339Nano
bs := e.e.blist.get(len(fmt))
bs = fmtTime(t, fmt, bs) // size bounded: no chance of realloc.
e.encStringBytesS(cborBaseString, stringView(bs))
e.e.blist.put(bs)
} else {
e.encUint(1, cborBaseTag)
t = t.UTC().Round(time.Microsecond)
Expand Down
4 changes: 2 additions & 2 deletions codec/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2803,7 +2803,7 @@ func freelistCapacity(length int) (capacity int) {
// bytesFreelist is a list of byte buffers, sorted by cap.
//
// In anecdotal testing (running go test -tsd 1..6), we couldn't get
// the length ofthe list > 4 at any time. So we believe a linear search
// the length of the list > 4 at any time. So we believe a linear search
// without bounds checking is sufficient.
//
// Typical usage model:
Expand All @@ -2821,7 +2821,7 @@ func freelistCapacity(length int) (capacity int) {
// v1 := v0
// ... use v1 ...
// blist.put(v1)
// if byteSliceAddr(v0) != byteSliceAddr(v1) {
// if !byteSliceSameData(v0, v1) {
// blist.put(v0)
// }
type bytesFreelist [][]byte
Expand Down