Skip to content

Commit 5d88971

Browse files
knweissmenghanl
authored andcommittedApr 16, 2018
Remove unnecessary type conversions (unconvert) (grpc#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
1 parent 7de9139 commit 5d88971

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed
 

‎interop/test_utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func DoServerStreaming(tc testpb.TestServiceClient, args ...grpc.CallOption) {
153153
grpclog.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
154154
}
155155
size := len(reply.GetPayload().GetBody())
156-
if size != int(respSizes[index]) {
156+
if size != respSizes[index] {
157157
grpclog.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
158158
}
159159
index++
@@ -198,7 +198,7 @@ func DoPingPong(tc testpb.TestServiceClient, args ...grpc.CallOption) {
198198
grpclog.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
199199
}
200200
size := len(reply.GetPayload().GetBody())
201-
if size != int(respSizes[index]) {
201+
if size != respSizes[index] {
202202
grpclog.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
203203
}
204204
index++

‎resolver/dns/dns_resolver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (d *dnsResolver) watcher() {
187187
result, sc := d.lookup()
188188
// Next lookup should happen after an interval defined by d.freq.
189189
d.t.Reset(d.freq)
190-
d.cc.NewServiceConfig(string(sc))
190+
d.cc.NewServiceConfig(sc)
191191
d.cc.NewAddress(result)
192192
}
193193
}

‎transport/flowcontrol.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ const (
3333
initialWindowSize = defaultWindowSize // for an RPC
3434
infinity = time.Duration(math.MaxInt64)
3535
defaultClientKeepaliveTime = infinity
36-
defaultClientKeepaliveTimeout = time.Duration(20 * time.Second)
36+
defaultClientKeepaliveTimeout = 20 * time.Second
3737
defaultMaxStreamsClient = 100
3838
defaultMaxConnectionIdle = infinity
3939
defaultMaxConnectionAge = infinity
4040
defaultMaxConnectionAgeGrace = infinity
41-
defaultServerKeepaliveTime = time.Duration(2 * time.Hour)
42-
defaultServerKeepaliveTimeout = time.Duration(20 * time.Second)
43-
defaultKeepalivePolicyMinTime = time.Duration(5 * time.Minute)
41+
defaultServerKeepaliveTime = 2 * time.Hour
42+
defaultServerKeepaliveTimeout = 20 * time.Second
43+
defaultKeepalivePolicyMinTime = 5 * time.Minute
4444
// max window limit set by HTTP2 Specs.
4545
maxWindowSize = math.MaxInt32
4646
// defaultWriteQuota is the default value for number of data

‎transport/http2_client.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ func (t *http2Client) updateFlowControl(n uint32) {
785785
ss: []http2.Setting{
786786
{
787787
ID: http2.SettingInitialWindowSize,
788-
Val: uint32(n),
788+
Val: n,
789789
},
790790
},
791791
})
@@ -795,7 +795,7 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
795795
size := f.Header().Length
796796
var sendBDPPing bool
797797
if t.bdpEst != nil {
798-
sendBDPPing = t.bdpEst.add(uint32(size))
798+
sendBDPPing = t.bdpEst.add(size)
799799
}
800800
// Decouple connection's flow control from application's read.
801801
// An update on connection's flow control should not depend on
@@ -806,7 +806,7 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
806806
// active(fast) streams from starving in presence of slow or
807807
// inactive streams.
808808
//
809-
if w := t.fc.onData(uint32(size)); w > 0 {
809+
if w := t.fc.onData(size); w > 0 {
810810
t.controlBuf.put(&outgoingWindowUpdate{
811811
streamID: 0,
812812
increment: w,
@@ -831,12 +831,12 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
831831
return
832832
}
833833
if size > 0 {
834-
if err := s.fc.onData(uint32(size)); err != nil {
834+
if err := s.fc.onData(size); err != nil {
835835
t.closeStream(s, io.EOF, true, http2.ErrCodeFlowControl, status.New(codes.Internal, err.Error()), nil)
836836
return
837837
}
838838
if f.Header().Flags.Has(http2.FlagDataPadded) {
839-
if w := s.fc.onRead(uint32(size) - uint32(len(f.Data()))); w > 0 {
839+
if w := s.fc.onRead(size - uint32(len(f.Data()))); w > 0 {
840840
t.controlBuf.put(&outgoingWindowUpdate{s.id, w})
841841
}
842842
}
@@ -861,12 +861,11 @@ func (t *http2Client) handleRSTStream(f *http2.RSTStreamFrame) {
861861
if !ok {
862862
return
863863
}
864-
code := http2.ErrCode(f.ErrCode)
865-
if code == http2.ErrCodeRefusedStream {
864+
if f.ErrCode == http2.ErrCodeRefusedStream {
866865
// The stream was unprocessed by the server.
867866
atomic.StoreUint32(&s.unprocessed, 1)
868867
}
869-
statusCode, ok := http2ErrConvTab[code]
868+
statusCode, ok := http2ErrConvTab[f.ErrCode]
870869
if !ok {
871870
warningf("transport: http2Client.handleRSTStream found no mapped gRPC status for the received http2 error %v", f.ErrCode)
872871
statusCode = codes.Unknown

‎transport/http2_server.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func (t *http2Server) updateFlowControl(n uint32) {
510510
ss: []http2.Setting{
511511
{
512512
ID: http2.SettingInitialWindowSize,
513-
Val: uint32(n),
513+
Val: n,
514514
},
515515
},
516516
})
@@ -521,7 +521,7 @@ func (t *http2Server) handleData(f *http2.DataFrame) {
521521
size := f.Header().Length
522522
var sendBDPPing bool
523523
if t.bdpEst != nil {
524-
sendBDPPing = t.bdpEst.add(uint32(size))
524+
sendBDPPing = t.bdpEst.add(size)
525525
}
526526
// Decouple connection's flow control from application's read.
527527
// An update on connection's flow control should not depend on
@@ -531,7 +531,7 @@ func (t *http2Server) handleData(f *http2.DataFrame) {
531531
// Decoupling the connection flow control will prevent other
532532
// active(fast) streams from starving in presence of slow or
533533
// inactive streams.
534-
if w := t.fc.onData(uint32(size)); w > 0 {
534+
if w := t.fc.onData(size); w > 0 {
535535
t.controlBuf.put(&outgoingWindowUpdate{
536536
streamID: 0,
537537
increment: w,
@@ -554,12 +554,12 @@ func (t *http2Server) handleData(f *http2.DataFrame) {
554554
return
555555
}
556556
if size > 0 {
557-
if err := s.fc.onData(uint32(size)); err != nil {
557+
if err := s.fc.onData(size); err != nil {
558558
t.closeStream(s, true, http2.ErrCodeFlowControl, nil)
559559
return
560560
}
561561
if f.Header().Flags.Has(http2.FlagDataPadded) {
562-
if w := s.fc.onRead(uint32(size) - uint32(len(f.Data()))); w > 0 {
562+
if w := s.fc.onRead(size - uint32(len(f.Data()))); w > 0 {
563563
t.controlBuf.put(&outgoingWindowUpdate{s.id, w})
564564
}
565565
}

‎transport/http_util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func (d *decodeState) processHeaderField(f hpack.HeaderField) error {
347347
errorf("Failed to decode metadata header (%q, %q): %v", f.Name, f.Value, err)
348348
return nil
349349
}
350-
d.addMetadata(f.Name, string(v))
350+
d.addMetadata(f.Name, v)
351351
}
352352
return nil
353353
}

0 commit comments

Comments
 (0)
Please sign in to comment.