mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
[decoder] remove unnecessary reference to a pointer
This commit is contained in:
@@ -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
@@ -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() {")
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package tests
|
||||
|
||||
type Struct1 struct {
|
||||
}
|
||||
|
||||
//easyjson:json
|
||||
type Struct2 struct {
|
||||
From *Struct1 `json:"from,omitempty"`
|
||||
Through *Struct1 `json:"through,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user