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

Use unsafe.Slice for WKB handling #411

Closed
peterstace opened this issue Aug 28, 2021 · 0 comments · Fixed by #454
Closed

Use unsafe.Slice for WKB handling #411

peterstace opened this issue Aug 28, 2021 · 0 comments · Fixed by #454
Assignees
Labels
good first issue Good for newcomers improve Improve (or remove) an existing feature

Comments

@peterstace
Copy link
Owner

peterstace commented Aug 28, 2021

Go 1.17 adds a new function unsafe.Slice. Currently, WKB marshalling/unmarshalling use unsafe in a few ways that are legal, but can be make safer and less error prone with unsafe.Slice.

E.g. rather than having the following code:

var floats []float64
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&floats))
hdr.Data = (*reflect.SliceHeader)(unsafe.Pointer(&byts)).Data
hdr.Len = len(byts) / 8
hdr.Cap = cap(byts) / 8
return floats

We can do something like this instead (untested):

return unsafe.Slice((*float64)(unsafe.Pointer(&byts[0])), len(byts)/8)

There may be a few other places in WKB marshalling/unmarshalling that we can cleanup using the new unsafe functions in Go 1.17.

@peterstace peterstace added good first issue Good for newcomers improve Improve (or remove) an existing feature labels Aug 30, 2021
@sameeraaperera sameeraaperera self-assigned this May 13, 2022
sameeraaperera added a commit that referenced this issue May 13, 2022
peterstace added a commit that referenced this issue May 13, 2022
…andling

#411 use safer method when converting between byte and float slices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers improve Improve (or remove) an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants