AlexStocks commented on code in PR #389:
URL: https://github.com/apache/dubbo-go-hessian2/pull/389#discussion_r3004225349


##########
string.go:
##########
@@ -38,13 +37,11 @@ import (
 // String
 // ///////////////////////////////////////
 // Slice convert string to byte slice
-func Slice(s string) (b []byte) {
-       pbytes := (*reflect.SliceHeader)(unsafe.Pointer(&b))
-       pstring := (*reflect.StringHeader)(unsafe.Pointer(&s))
-       pbytes.Data = pstring.Data
-       pbytes.Len = pstring.Len
-       pbytes.Cap = pstring.Len
-       return
+func Slice(s string) []byte {

Review Comment:
   [P1] 使用 unsafe.Slice 替代 reflect.SliceHeader 符合 Go 1.17+ 最佳实践。但需注意返回的 slice 
与原 string 共享底层数据,修改 slice 会导致 undefined behavior。建议添加注释警告不可修改返回的 slice。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to