-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from tdakkota/feat/unsafe-copying
feat(proto): use memmove on amd64 for int columns
- Loading branch information
Showing
74 changed files
with
1,577 additions
and
737 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{{- /*gotype: github.com/go-faster/ch/proto/cmd/ch-gen-col.Variant*/ -}} | ||
{{ if .GenerateUnsafe }}//go:build !amd64 || nounsafe{{ end }} | ||
// Code generated by ./cmd/ch-gen-int, DO NOT EDIT. | ||
|
||
package proto | ||
|
||
import ( | ||
"encoding/binary" | ||
{{- if .IsFloat }} | ||
"math" | ||
{{- end }} | ||
|
||
"github.com/go-faster/errors" | ||
) | ||
|
||
var _ = binary.LittleEndian // clickHouse uses LittleEndian | ||
|
||
// DecodeColumn decodes {{ .Name }} rows from *Reader. | ||
func (c *{{ .Type }}) DecodeColumn(r *Reader, rows int) error { | ||
if rows == 0 { | ||
return nil | ||
} | ||
{{- if .SingleByte }} | ||
data, err := r.ReadRaw(rows) | ||
{{- else }} | ||
const size = {{ .Bits }} / 8 | ||
data, err := r.ReadRaw(rows * size) | ||
{{- end }} | ||
if err != nil { | ||
return errors.Wrap(err, "read") | ||
} | ||
{{- if .Byte }} | ||
*c = append(*c, data...) | ||
{{- else if .SingleByte }} | ||
v := *c | ||
v = append(v, make([]{{ .ElemType }}, rows)...) | ||
for i := range data { | ||
v[i] = {{ .ElemType }}(data[i]) | ||
} | ||
*c = v | ||
{{- else }} | ||
v := *c | ||
// Move bound check out of loop. | ||
// | ||
// See https://github.com/golang/go/issues/30945. | ||
_ = data[len(data)-size] | ||
for i := 0; i <= len(data)-size; i += size { | ||
v = append(v, | ||
{{- if .IsFloat }} | ||
math.{{ .Name }}frombits(bin.{{ .BinFunc }}(data[i:i+size])), | ||
{{- else if .Cast }} | ||
{{ .ElemType }}({{ .BinGet }}(data[i:i+size])), | ||
{{- else }} | ||
{{ .BinGet }}(data[i:i+size]), | ||
{{- end }} | ||
) | ||
} | ||
*c = v | ||
{{- end }} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{{- /*gotype: github.com/go-faster/ch/proto/cmd/ch-gen-col.Variant*/ -}} | ||
//go:build amd64 && !nounsafe | ||
// Code generated by ./cmd/ch-gen-int, DO NOT EDIT. | ||
|
||
package proto | ||
|
||
import ( | ||
"unsafe" | ||
"reflect" | ||
|
||
"github.com/go-faster/errors" | ||
) | ||
|
||
// DecodeColumn decodes {{ .Name }} rows from *Reader. | ||
func (c *{{ .Type }}) DecodeColumn(r *Reader, rows int) error { | ||
if rows == 0 { | ||
return nil | ||
} | ||
*c = append(*c, make([]{{ .ElemType }}, rows)...) | ||
s := *(*reflect.SliceHeader)(unsafe.Pointer(c)) | ||
{{- if not .SingleByte }} | ||
s.Len *= {{ .Bytes }} | ||
s.Cap *= {{ .Bytes }} | ||
{{- end }} | ||
dst := *(*[]byte)(unsafe.Pointer(&s)) | ||
if err := r.ReadFull(dst); err != nil { | ||
return errors.Wrap(err, "read full") | ||
} | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.