Skip to content

Commit

Permalink
Merge pull request #101 from ScaleChamp/master
Browse files Browse the repository at this point in the history
Reduce unencodeValue allocations
  • Loading branch information
worg authored May 9, 2021
2 parents 68b55a5 + f65d066 commit f6b94db
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion frame/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package frame

import (
"strings"
"unsafe"
)

var (
Expand All @@ -19,9 +20,15 @@ var (
)
)

// Reduce one allocation on copying bytes to string
func bytesToString(b []byte) string {
/* #nosec G103 */
return *(*string)(unsafe.Pointer(&b))
}

// Unencodes a header value using STOMP value encoding
// TODO: return error if invalid sequences found (eg "\t")
func unencodeValue(b []byte) (string, error) {
s := replacerForUnencodeValue.Replace(string(b))
s := replacerForUnencodeValue.Replace(bytesToString(b))
return s, nil
}

0 comments on commit f6b94db

Please sign in to comment.