|
@@ -16,7 +16,7 @@ type unsafeString struct {
|
|
|
Len int
|
|
Len int
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-type unsafeBytes struct {
|
|
|
|
|
|
|
+type unsafeSlice struct {
|
|
|
Data uintptr
|
|
Data uintptr
|
|
|
Len int
|
|
Len int
|
|
|
Cap int
|
|
Cap int
|
|
@@ -29,8 +29,10 @@ func stringView(v []byte) string {
|
|
|
if len(v) == 0 {
|
|
if len(v) == 0 {
|
|
|
return ""
|
|
return ""
|
|
|
}
|
|
}
|
|
|
- x := unsafeString{uintptr(unsafe.Pointer(&v[0])), len(v)}
|
|
|
|
|
- return *(*string)(unsafe.Pointer(&x))
|
|
|
|
|
|
|
+
|
|
|
|
|
+ bx := (*unsafeSlice)(unsafe.Pointer(&v))
|
|
|
|
|
+ sx := unsafeString{bx.Data, bx.Len}
|
|
|
|
|
+ return *(*string)(unsafe.Pointer(&sx))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// bytesView returns a view of the string as a []byte.
|
|
// bytesView returns a view of the string as a []byte.
|
|
@@ -40,6 +42,8 @@ func bytesView(v string) []byte {
|
|
|
if len(v) == 0 {
|
|
if len(v) == 0 {
|
|
|
return zeroByteSlice
|
|
return zeroByteSlice
|
|
|
}
|
|
}
|
|
|
- x := unsafeBytes{uintptr(unsafe.Pointer(&v)), len(v), len(v)}
|
|
|
|
|
- return *(*[]byte)(unsafe.Pointer(&x))
|
|
|
|
|
|
|
+
|
|
|
|
|
+ sx := (*unsafeString)(unsafe.Pointer(&v))
|
|
|
|
|
+ bx := unsafeSlice{sx.Data, sx.Len, sx.Len}
|
|
|
|
|
+ return *(*[]byte)(unsafe.Pointer(&bx))
|
|
|
}
|
|
}
|