fastjson icon indicating copy to clipboard operation
fastjson copied to clipboard

func s2s use deprecated code in golang 1.20

Open tvojacek opened this issue 1 year ago • 0 comments

Same problem has been solved in fasthttp in https://github.com/valyala/fasthttp/pull/1481 Original code: func s2b(s string) (b []byte) { strh := (*reflect.StringHeader)(unsafe.Pointer(&s)) sh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) sh.Data = strh.Data sh.Len = strh.Len sh.Cap = strh.Len return b }

Was replaced in b2s_new.go // s2b converts string to a byte slice without memory allocation. func s2b(s string) []byte { return unsafe.Slice(unsafe.StringData(s), len(s)) }

tvojacek avatar Oct 16 '23 22:10 tvojacek