From 3b57484e5b5f43c71f60fa434b2167d7c99b2397 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 17 Mar 2017 11:54:20 -0400 Subject: [PATCH] Remove unncessary conversions Found with github.com/mdempsky/unconvert. /Users/tamird/src/go/src/github.com/golang/protobuf/jsonpb/jsonpb.go:625:32: unnecessary conversion /Users/tamird/src/go/src/github.com/golang/protobuf/proto/encode.go:177:30: unnecessary conversion /Users/tamird/src/go/src/github.com/golang/protobuf/proto/encode.go:181:26: unnecessary conversion /Users/tamird/src/go/src/github.com/golang/protobuf/proto/text_parser.go:868:21: unnecessary conversion --- jsonpb/jsonpb.go | 2 +- proto/encode.go | 4 ++-- proto/text_parser.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jsonpb/jsonpb.go b/jsonpb/jsonpb.go index c7a45d6f09..412ba1ce4d 100644 --- a/jsonpb/jsonpb.go +++ b/jsonpb/jsonpb.go @@ -753,7 +753,7 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe if err != nil { return fmt.Errorf("bad Timestamp: %v", err) } - target.Field(0).SetInt(int64(t.Unix())) + target.Field(0).SetInt(t.Unix()) target.Field(1).SetInt(int64(t.Nanosecond())) return nil case "Struct": diff --git a/proto/encode.go b/proto/encode.go index 2b30f84626..8b84d1b22d 100644 --- a/proto/encode.go +++ b/proto/encode.go @@ -174,11 +174,11 @@ func sizeFixed32(x uint64) int { // This is the format used for the sint64 protocol buffer type. func (p *Buffer) EncodeZigzag64(x uint64) error { // use signed number to get arithmetic right shift. - return p.EncodeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63)))) + return p.EncodeVarint((x << 1) ^ uint64((int64(x) >> 63))) } func sizeZigzag64(x uint64) int { - return sizeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63)))) + return sizeVarint((x << 1) ^ uint64((int64(x) >> 63))) } // EncodeZigzag32 writes a zigzag-encoded 32-bit integer diff --git a/proto/text_parser.go b/proto/text_parser.go index 61f83c1e10..5e14513f28 100644 --- a/proto/text_parser.go +++ b/proto/text_parser.go @@ -865,7 +865,7 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) error { return p.readStruct(fv, terminator) case reflect.Uint32: if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil { - fv.SetUint(uint64(x)) + fv.SetUint(x) return nil } case reflect.Uint64: