bytedance / sonic

A blazingly fast JSON serializing & deserializing library
Apache License 2.0
6.71k stars 333 forks source link

chore: use out.String() instead of string(out.Bytes()) #557

Closed testwill closed 9 months ago

CLAassistant commented 9 months ago

CLA assistant check
All committers have signed the CLA.

AsterDY commented 9 months ago

both are copy string, no difference...

testwill commented 9 months ago

bytes.Buffer has both a String and a Bytes method. It is almost never necessary to use string(buf.Bytes()) or []byte(buf.String()) – simply use the other method.

The only exception to this are map lookups. Due to a compiler optimization, m[string(buf.Bytes())] is more efficient than m[buf.String()]. staticcheck