-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
001986a
commit 56efc67
Showing
5 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
package moira | ||
|
||
import ( | ||
"reflect" | ||
"unsafe" | ||
) | ||
|
||
// UnsafeBytesToString converts source to string without copying. | ||
func UnsafeBytesToString(b []byte) string { | ||
return *(*string)(unsafe.Pointer(&b)) | ||
return unsafe.String(unsafe.SliceData(b), len(b)) | ||
} | ||
|
||
// UnsafeStringToBytes converts string to source without copying. | ||
func UnsafeStringToBytes(s string) []byte { | ||
var b []byte | ||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) | ||
bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data | ||
bh.Len = len(s) | ||
bh.Cap = len(s) | ||
|
||
return b | ||
return unsafe.Slice(unsafe.StringData(s), len(s)) | ||
} |