[decoder] remove unnecessary reference to a pointer

This commit is contained in:
Aleksandr Petrukhin
2019-02-20 21:52:23 +00:00
parent 60711f1a83
commit b27fccced4
3 changed files with 19 additions and 2 deletions
+3 -1
View File
@@ -25,7 +25,8 @@ generate: root build
.root/src/$(PKG)/tests/nothing.go \
.root/src/$(PKG)/tests/named_type.go \
.root/src/$(PKG)/tests/custom_map_key_type.go \
.root/src/$(PKG)/tests/embedded_type.go
.root/src/$(PKG)/tests/embedded_type.go \
.root/src/$(PKG)/tests/reference_to_pointer.go
.root/bin/easyjson -all .root/src/$(PKG)/tests/data.go
.root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go
@@ -37,6 +38,7 @@ generate: root build
.root/bin/easyjson .root/src/$(PKG)/tests/named_type.go
.root/bin/easyjson .root/src/$(PKG)/tests/custom_map_key_type.go
.root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go
.root/bin/easyjson .root/src/$(PKG)/tests/reference_to_pointer.go
.root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go
test: generate root
+6 -1
View File
@@ -198,7 +198,12 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field
dec := g.getDecoderName(t)
g.addType(t)
fmt.Fprintln(g.out, ws+dec+"(in, &"+out+")")
if len(out) > 0 && out[0] == '*' {
// NOTE: In order to remove an extra reference to a pointer
fmt.Fprintln(g.out, ws+dec+"(in, "+out[1:]+")")
} else {
fmt.Fprintln(g.out, ws+dec+"(in, &"+out+")")
}
case reflect.Ptr:
fmt.Fprintln(g.out, ws+"if in.IsNull() {")
+10
View File
@@ -0,0 +1,10 @@
package tests
type Struct1 struct {
}
//easyjson:json
type Struct2 struct {
From *Struct1 `json:"from,omitempty"`
Through *Struct1 `json:"through,omitempty"`
}