diff options
Diffstat (limited to 'vendor/github.com/yuin/goldmark/util/util_unsafe.go')
| -rw-r--r-- | vendor/github.com/yuin/goldmark/util/util_unsafe.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/vendor/github.com/yuin/goldmark/util/util_unsafe.go b/vendor/github.com/yuin/goldmark/util/util_unsafe.go new file mode 100644 index 0000000..d098811 --- /dev/null +++ b/vendor/github.com/yuin/goldmark/util/util_unsafe.go | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | // +build !appengine,!js | ||
| 2 | |||
| 3 | package util | ||
| 4 | |||
| 5 | import ( | ||
| 6 | "reflect" | ||
| 7 | "unsafe" | ||
| 8 | ) | ||
| 9 | |||
| 10 | // BytesToReadOnlyString returns a string converted from given bytes. | ||
| 11 | func BytesToReadOnlyString(b []byte) string { | ||
| 12 | return *(*string)(unsafe.Pointer(&b)) | ||
| 13 | } | ||
| 14 | |||
| 15 | // StringToReadOnlyBytes returns bytes converted from given string. | ||
| 16 | func StringToReadOnlyBytes(s string) (bs []byte) { | ||
| 17 | sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) | ||
| 18 | bh := (*reflect.SliceHeader)(unsafe.Pointer(&bs)) | ||
| 19 | bh.Data = sh.Data | ||
| 20 | bh.Cap = sh.Len | ||
| 21 | bh.Len = sh.Len | ||
| 22 | return | ||
| 23 | } | ||
