mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 04:27:54 +00:00
Merge pull request #75693 from smarterclayton/speed_up_time_json
Reduce allocations in metav1.Time JSON serialization
This commit is contained in:
commit
152f0a150e
@ -20,7 +20,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/gofuzz"
|
fuzz "github.com/google/gofuzz"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Time is a wrapper around time.Time which supports correct
|
// Time is a wrapper around time.Time which supports correct
|
||||||
@ -147,8 +147,12 @@ func (t Time) MarshalJSON() ([]byte, error) {
|
|||||||
// Encode unset/nil objects as JSON's "null".
|
// Encode unset/nil objects as JSON's "null".
|
||||||
return []byte("null"), nil
|
return []byte("null"), nil
|
||||||
}
|
}
|
||||||
|
buf := make([]byte, 0, len(time.RFC3339)+2)
|
||||||
return json.Marshal(t.UTC().Format(time.RFC3339))
|
buf = append(buf, '"')
|
||||||
|
// time cannot contain non escapable JSON characters
|
||||||
|
buf = t.UTC().AppendFormat(buf, time.RFC3339)
|
||||||
|
buf = append(buf, '"')
|
||||||
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenAPISchemaType is used by the kube-openapi generator when constructing
|
// OpenAPISchemaType is used by the kube-openapi generator when constructing
|
||||||
|
Loading…
Reference in New Issue
Block a user