Remove unnecessary type conversions (unconvert) (#1995)

This fixes:
grpc/interop/test_utils.go:156:17: unnecessary conversion
interop/test_utils.go:201:17: unnecessary conversion
resolver/dns/dns_resolver.go:190:31: unnecessary conversion
transport/flowcontrol.go:36:47: unnecessary conversion
transport/flowcontrol.go:41:47: unnecessary conversion
transport/flowcontrol.go:42:47: unnecessary conversion
transport/flowcontrol.go:43:47: unnecessary conversion
transport/http2_client.go:788:16: unnecessary conversion
transport/http2_client.go:798:36: unnecessary conversion
transport/http2_client.go:809:28: unnecessary conversion
transport/http2_client.go:834:31: unnecessary conversion
transport/http2_client.go:839:30: unnecessary conversion
transport/http2_client.go:864:23: unnecessary conversion
transport/http2_server.go:513:16: unnecessary conversion
transport/http2_server.go:524:36: unnecessary conversion
transport/http2_server.go:534:28: unnecessary conversion
transport/http2_server.go:557:31: unnecessary conversion
transport/http2_server.go:562:30: unnecessary conversion
transport/http_util.go:350:31: unnecessary conversion
This commit is contained in:
Karsten Weiss 2018-04-16 19:18:17 +02:00 committed by Menghan Li
parent 7de9139327
commit 5d8897144f
6 changed files with 20 additions and 21 deletions

View File

@ -153,7 +153,7 @@ func DoServerStreaming(tc testpb.TestServiceClient, args ...grpc.CallOption) {
grpclog.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
}
size := len(reply.GetPayload().GetBody())
if size != int(respSizes[index]) {
if size != respSizes[index] {
grpclog.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
}
index++
@ -198,7 +198,7 @@ func DoPingPong(tc testpb.TestServiceClient, args ...grpc.CallOption) {
grpclog.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
}
size := len(reply.GetPayload().GetBody())
if size != int(respSizes[index]) {
if size != respSizes[index] {
grpclog.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
}
index++

View File

@ -187,7 +187,7 @@ func (d *dnsResolver) watcher() {
result, sc := d.lookup()
// Next lookup should happen after an interval defined by d.freq.
d.t.Reset(d.freq)
d.cc.NewServiceConfig(string(sc))
d.cc.NewServiceConfig(sc)
d.cc.NewAddress(result)
}
}

View File

@ -33,14 +33,14 @@ const (
initialWindowSize = defaultWindowSize // for an RPC
infinity = time.Duration(math.MaxInt64)
defaultClientKeepaliveTime = infinity
defaultClientKeepaliveTimeout = time.Duration(20 * time.Second)
defaultClientKeepaliveTimeout = 20 * time.Second
defaultMaxStreamsClient = 100
defaultMaxConnectionIdle = infinity
defaultMaxConnectionAge = infinity
defaultMaxConnectionAgeGrace = infinity
defaultServerKeepaliveTime = time.Duration(2 * time.Hour)
defaultServerKeepaliveTimeout = time.Duration(20 * time.Second)
defaultKeepalivePolicyMinTime = time.Duration(5 * time.Minute)
defaultServerKeepaliveTime = 2 * time.Hour
defaultServerKeepaliveTimeout = 20 * time.Second
defaultKeepalivePolicyMinTime = 5 * time.Minute
// max window limit set by HTTP2 Specs.
maxWindowSize = math.MaxInt32
// defaultWriteQuota is the default value for number of data

View File

@ -785,7 +785,7 @@ func (t *http2Client) updateFlowControl(n uint32) {
ss: []http2.Setting{
{
ID: http2.SettingInitialWindowSize,
Val: uint32(n),
Val: n,
},
},
})
@ -795,7 +795,7 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
size := f.Header().Length
var sendBDPPing bool
if t.bdpEst != nil {
sendBDPPing = t.bdpEst.add(uint32(size))
sendBDPPing = t.bdpEst.add(size)
}
// Decouple connection's flow control from application's read.
// An update on connection's flow control should not depend on
@ -806,7 +806,7 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
// active(fast) streams from starving in presence of slow or
// inactive streams.
//
if w := t.fc.onData(uint32(size)); w > 0 {
if w := t.fc.onData(size); w > 0 {
t.controlBuf.put(&outgoingWindowUpdate{
streamID: 0,
increment: w,
@ -831,12 +831,12 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
return
}
if size > 0 {
if err := s.fc.onData(uint32(size)); err != nil {
if err := s.fc.onData(size); err != nil {
t.closeStream(s, io.EOF, true, http2.ErrCodeFlowControl, status.New(codes.Internal, err.Error()), nil)
return
}
if f.Header().Flags.Has(http2.FlagDataPadded) {
if w := s.fc.onRead(uint32(size) - uint32(len(f.Data()))); w > 0 {
if w := s.fc.onRead(size - uint32(len(f.Data()))); w > 0 {
t.controlBuf.put(&outgoingWindowUpdate{s.id, w})
}
}
@ -861,12 +861,11 @@ func (t *http2Client) handleRSTStream(f *http2.RSTStreamFrame) {
if !ok {
return
}
code := http2.ErrCode(f.ErrCode)
if code == http2.ErrCodeRefusedStream {
if f.ErrCode == http2.ErrCodeRefusedStream {
// The stream was unprocessed by the server.
atomic.StoreUint32(&s.unprocessed, 1)
}
statusCode, ok := http2ErrConvTab[code]
statusCode, ok := http2ErrConvTab[f.ErrCode]
if !ok {
warningf("transport: http2Client.handleRSTStream found no mapped gRPC status for the received http2 error %v", f.ErrCode)
statusCode = codes.Unknown

View File

@ -510,7 +510,7 @@ func (t *http2Server) updateFlowControl(n uint32) {
ss: []http2.Setting{
{
ID: http2.SettingInitialWindowSize,
Val: uint32(n),
Val: n,
},
},
})
@ -521,7 +521,7 @@ func (t *http2Server) handleData(f *http2.DataFrame) {
size := f.Header().Length
var sendBDPPing bool
if t.bdpEst != nil {
sendBDPPing = t.bdpEst.add(uint32(size))
sendBDPPing = t.bdpEst.add(size)
}
// Decouple connection's flow control from application's read.
// An update on connection's flow control should not depend on
@ -531,7 +531,7 @@ func (t *http2Server) handleData(f *http2.DataFrame) {
// Decoupling the connection flow control will prevent other
// active(fast) streams from starving in presence of slow or
// inactive streams.
if w := t.fc.onData(uint32(size)); w > 0 {
if w := t.fc.onData(size); w > 0 {
t.controlBuf.put(&outgoingWindowUpdate{
streamID: 0,
increment: w,
@ -554,12 +554,12 @@ func (t *http2Server) handleData(f *http2.DataFrame) {
return
}
if size > 0 {
if err := s.fc.onData(uint32(size)); err != nil {
if err := s.fc.onData(size); err != nil {
t.closeStream(s, true, http2.ErrCodeFlowControl, nil)
return
}
if f.Header().Flags.Has(http2.FlagDataPadded) {
if w := s.fc.onRead(uint32(size) - uint32(len(f.Data()))); w > 0 {
if w := s.fc.onRead(size - uint32(len(f.Data()))); w > 0 {
t.controlBuf.put(&outgoingWindowUpdate{s.id, w})
}
}

View File

@ -347,7 +347,7 @@ func (d *decodeState) processHeaderField(f hpack.HeaderField) error {
errorf("Failed to decode metadata header (%q, %q): %v", f.Name, f.Value, err)
return nil
}
d.addMetadata(f.Name, string(v))
d.addMetadata(f.Name, v)
}
return nil
}