Skip to content

Commit

Permalink
fix: avoid redundant byte conversion in UnmarshalText
Browse files Browse the repository at this point in the history
  • Loading branch information
mdawar committed Oct 16, 2024
1 parent 03bb797 commit c2a76fa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ func (d *Decimal) UnmarshalJSON(data []byte) error {

// MarshalText implements the [encoding.TextMarshaler] interface.
func (d Decimal) MarshalText() ([]byte, error) {
return []byte(d.String()), nil
if !d.coef.overflow() {
// Return without quotes.
return d.bytesU128(true, false), nil
}

return []byte(d.stringBigInt(true)), nil
}

// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
Expand Down

0 comments on commit c2a76fa

Please sign in to comment.