Skip to content

Commit

Permalink
fix: reduce alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Dec 11, 2024
1 parent f4e48f1 commit f14b2c2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ func (cfg frozenConfig) MarshalIndent(val interface{}, prefix, indent string) ([

// UnmarshalFromString is implemented by sonic
func (cfg frozenConfig) UnmarshalFromString(buf string, val interface{}) error {
r := bytes.NewBufferString(buf)
return cfg.Unmarshal([]byte(buf), val)
}

// Unmarshal is implemented by sonic
func (cfg frozenConfig) Unmarshal(buf []byte, val interface{}) error {
r := bytes.NewBuffer(buf)
dec := json.NewDecoder(r)
if cfg.UseNumber {
dec.UseNumber()
Expand All @@ -88,11 +93,6 @@ func (cfg frozenConfig) UnmarshalFromString(buf string, val interface{}) error {
return dec.Decode(val)
}

// Unmarshal is implemented by sonic
func (cfg frozenConfig) Unmarshal(buf []byte, val interface{}) error {
return cfg.UnmarshalFromString(string(buf), val)
}

// NewEncoder is implemented by sonic
func (cfg frozenConfig) NewEncoder(writer io.Writer) Encoder {
enc := json.NewEncoder(writer)
Expand Down

0 comments on commit f14b2c2

Please sign in to comment.