Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to go 1.20 #70

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Go

env:
go-version: "1.19"

on:
pull_request:
push:
Expand All @@ -17,7 +14,8 @@ jobs:
- name: set up go
uses: actions/setup-go@v4
with:
go-version: ${{ env.go-version }}
check-latest: true
go-version-file: "go.mod"
- name: fmt, tidy
run: |
make install
Expand All @@ -35,7 +33,8 @@ jobs:
- name: set up go
uses: actions/setup-go@v4
with:
go-version: ${{ env.go-version }}
check-latest: true
go-version-file: "go.mod"
- name: setup env
run: make install
- name: lint
Expand All @@ -57,7 +56,8 @@ jobs:
- name: set up go
uses: actions/setup-go@v4
with:
go-version: ${{ env.go-version }}
check-latest: true
go-version-file: "go.mod"
- name: setup env
run: make install
- name: Clear test cache
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/spacemeshos/go-scale

go 1.19
go 1.20

require (
github.com/google/go-cmp v0.5.9
Expand Down
16 changes: 8 additions & 8 deletions unsafe.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package scale

import (
"reflect"
"unsafe"
)

// stringToBytes converts a string to a byte slice without copying the underlying data.
// IMPORTANT: The returned byte slice must not be modified!
// This is a low-level function and should be used carefully.
func stringToBytes(s string) (b []byte) {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Cap = sh.Len
bh.Len = sh.Len
return b
if s == "" {
return nil
}
return unsafe.Slice(unsafe.StringData(s), len(s))
}

// bytesToString converts a byte slice to a string without copying the underlying data.
// This is a low-level function and should be used carefully.
func bytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
if len(b) == 0 {
return ""
}
return unsafe.String(unsafe.SliceData(b), len(b))
}