Refactor encoding to use *string instead of string as input

I don't want to clone the whole input string
This commit is contained in:
2024-07-31 12:58:02 +02:00
parent 7b4fcf3de1
commit 7001f2c51a
5 changed files with 19 additions and 18 deletions

View File

@@ -11,15 +11,15 @@ type GSM7Coder struct{}
// Otherwise Encode will allocate memory as it sees fit
// Which is fine but not optimal
// Preallocate the buffer with the size of EncodesInto bytes
func (c *GSM7Coder) Encode(s string, buf *bytes.Buffer) error {
func (c *GSM7Coder) Encode(s *string, buf *bytes.Buffer) error {
// utf8 := *(*[]byte)(unsafe.Pointer(&s))
utf8 := []byte(s)
utf8 := []byte(*s)
var (
offset int = 1
bitshift byte = 0
leap, shift bool
)
encodedSize := GSM7EncodesInto(&s)
encodedSize := GSM7EncodesInto(s)
cap := buf.Cap()
if cap < encodedSize {
buf.Grow(encodedSize - cap)