Skip to content

Commit

Permalink
fixing lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Jan 8, 2024
1 parent 1928a76 commit 9e952e8
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package alterx

import (
"fmt"
"reflect"
"regexp"
"strings"
"unsafe"
Expand Down Expand Up @@ -50,12 +49,11 @@ func checkMissing(template string, data map[string]interface{}) error {
return nil
}

// TODO: add this to utils
// unsafeToBytes converts a string to byte slice and does it with
// zero allocations.
//
// Reference - https://stackoverflow.com/questions/59209493/how-to-use-unsafe-get-a-byte-slice-from-a-string-without-memory-copy
func unsafeToBytes(data string) []byte {
var buf = *(*[]byte)(unsafe.Pointer(&data))
(*reflect.SliceHeader)(unsafe.Pointer(&buf)).Cap = len(data)
return buf
return unsafe.Slice(unsafe.StringData(data), len(data))
}

0 comments on commit 9e952e8

Please sign in to comment.