Skip to content

Commit c0f2d24

Browse files
authored
datetime and safelong: MarshalText implementations avoid string->[]byte conversion (#380)
1 parent ad56f61 commit c0f2d24

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

datetime/datetime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (d DateTime) String() string {
1919

2020
// MarshalText implements encoding.TextMarshaler (used by encoding/json and others).
2121
func (d DateTime) MarshalText() ([]byte, error) {
22-
return []byte(d.String()), nil
22+
return time.Time(d).AppendFormat(nil, time.RFC3339Nano), nil
2323
}
2424

2525
// UnmarshalText implements encoding.TextUnmarshaler (used by encoding/json and others).

safelong/safelong.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (s SafeLong) MarshalJSON() ([]byte, error) {
5252
if err := validate(int64(s)); err != nil {
5353
return nil, err
5454
}
55-
return json.Marshal(int64(s))
55+
return strconv.AppendInt(nil, int64(s), 10), nil
5656
}
5757

5858
func validate(val int64) error {

0 commit comments

Comments
 (0)