mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-05 02:59:44 -06:00
This changes equal to compare by ref. Since computing the ref can be expensive we first check that the type refs are equal. Fixes #532
47 lines
1.1 KiB
Cheetah
47 lines
1.1 KiB
Cheetah
{{$typesPackage := .TypesPackage}}
|
|
|
|
// {{.Name}}
|
|
|
|
type {{.Name}} struct {
|
|
target ref.Ref
|
|
ref *ref.Ref
|
|
}
|
|
|
|
func New{{.Name}}(target ref.Ref) {{.Name}} {
|
|
return {{.Name}}{target, &ref.Ref{}}
|
|
}
|
|
|
|
func (r {{.Name}}) TargetRef() ref.Ref {
|
|
return r.target
|
|
}
|
|
|
|
func (r {{.Name}}) Ref() ref.Ref {
|
|
return {{$typesPackage}}EnsureRef(r.ref, r)
|
|
}
|
|
|
|
func (r {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
|
|
return other != nil && __typeRefFor{{.Name}}.Equals(other.TypeRef()) && r.Ref() == other.Ref()
|
|
}
|
|
|
|
func (r {{.Name}}) Chunks() []ref.Ref {
|
|
return r.TypeRef().Chunks()
|
|
}
|
|
|
|
func {{.Name}}FromVal(val {{$typesPackage}}Value) {{.Name}} {
|
|
// TODO: Do we still need FromVal?
|
|
if val, ok := val.({{.Name}}); ok {
|
|
return val
|
|
}
|
|
return New{{.Name}}(val.({{$typesPackage}}Ref).TargetRef())
|
|
}
|
|
|
|
{{template "type_ref.tmpl" .}}
|
|
|
|
func (r {{.Name}}) TargetValue(cs chunks.ChunkSource) {{userType .ElemType}} {
|
|
return {{valueToUser (printf "%sReadValue(r.target, cs)" $typesPackage) .ElemType}}
|
|
}
|
|
|
|
func (r {{.Name}}) SetTargetValue(val {{userType .ElemType}}, cs chunks.ChunkSink) {{.Name}} {
|
|
return New{{.Name}}({{$typesPackage}}WriteValue({{userToValue "val" .ElemType}}, cs))
|
|
}
|