diff options
author | Valery Piashchynski <[email protected]> | 2021-02-05 23:10:50 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-02-05 23:10:50 +0300 |
commit | 11b357c4457dfcbc1ef79478c200b794b5486b13 (patch) | |
tree | 29b512baf4d6a8ef79e19a0de3a9e642871b6d4e /pkg/payload | |
parent | 6c8cf12de734f01a0f0cdc4d2b55973cc8d1ddf1 (diff) |
Faster toString convertation (only for the english)
Diffstat (limited to 'pkg/payload')
-rwxr-xr-x | pkg/payload/payload.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/pkg/payload/payload.go b/pkg/payload/payload.go index fac36852..bebe8df1 100755 --- a/pkg/payload/payload.go +++ b/pkg/payload/payload.go @@ -1,5 +1,7 @@ package payload +import "unsafe" + // Payload carries binary header and body to stack and // back to the server. type Payload struct { @@ -12,5 +14,10 @@ type Payload struct { // String returns payload body as string func (p *Payload) String() string { - return string(p.Body) + return toString(p.Body) } + +// unsafe, but lightning fast []byte to string conversion +func toString(data []byte) string { + return *(*string)(unsafe.Pointer(&data)) +}
\ No newline at end of file |