Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiang <[email protected]>
  • Loading branch information
dongjiang1989 committed Dec 13, 2024
1 parent 32a503d commit 9951071
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: Install StaticCheck
run: go install honnef.co/go/tools/cmd/staticcheck@2022.1
run: go install honnef.co/go/tools/cmd/staticcheck@2024.1.1

- name: Cache Go Dependencies
uses: actions/cache@v2
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func SliceRandList(min, max int) []int {
}
length := max - min + 1
t0 := time.Now()
rand.Seed(int64(t0.Nanosecond()))
list := rand.Perm(length)
r := rand.New(rand.NewSource(int64(t0.Nanosecond())))
list := r.Perm(length)
for index := range list {
list[index] += min
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/utils/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package utils

import (
"reflect"
"strings"
"unsafe"
)
Expand Down Expand Up @@ -66,16 +65,17 @@ func Substr(str string, start, length int) string {
return string(rs[start:end])
}

func String2Bytes(s string) (b []byte) {
bs := (*reflect.SliceHeader)(unsafe.Pointer(&b))
ss := (*reflect.StringHeader)(unsafe.Pointer(&s))
bs.Data = ss.Data
bs.Len = ss.Len
bs.Cap = ss.Len
return b
func String2Bytes(s string) []byte {
var ret []byte
if len(s) == 0 {
return ret
}
return unsafe.Slice(unsafe.StringData(s), len(s))
}

func Bytes2String(b []byte) (s string) {
s = *(*string)(unsafe.Pointer(&b))
return s
func Bytes2String(b []byte) string {
if len(b) == 0 {
return ""
}
return unsafe.String(&b[0], len(b))
}

0 comments on commit 9951071

Please sign in to comment.