Refactor to use UnsafeStringToBytes (#31358)
The PR replaces all `goldmark/util.BytesToReadOnlyString` with `util.UnsafeBytesToString`, `goldmark/util.StringToReadOnlyBytes` with `util.UnsafeStringToBytes`. This removes one `TODO`. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> (cherry picked from commit 1761459ebc7eb6d432eced093b4583425a5c5d4b)
This commit is contained in:
parent
b5ea092964
commit
b640ac4660
6 changed files with 14 additions and 18 deletions
|
@ -87,11 +87,11 @@ func ToSnakeCase(input string) string {
|
|||
}
|
||||
|
||||
// UnsafeBytesToString uses Go's unsafe package to convert a byte slice to a string.
|
||||
// TODO: replace all "goldmark/util.BytesToReadOnlyString" with this official approach
|
||||
func UnsafeBytesToString(b []byte) string {
|
||||
return unsafe.String(unsafe.SliceData(b), len(b))
|
||||
}
|
||||
|
||||
// UnsafeStringToBytes uses Go's unsafe package to convert a string to a byte slice.
|
||||
func UnsafeStringToBytes(s string) []byte {
|
||||
return unsafe.Slice(unsafe.StringData(s), len(s))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue