status: avoid allocations when returning an OK status (#2929)

This commit is contained in:
David Zbarsky 2019-07-24 13:57:23 -04:00 committed by Doug Fawley
parent decb43806d
commit 5da5b1f225
1 changed files with 2 additions and 2 deletions

View File

@ -132,7 +132,7 @@ func FromProto(s *spb.Status) *Status {
// Status is returned with codes.Unknown and the original error message.
func FromError(err error) (s *Status, ok bool) {
if err == nil {
return &Status{s: &spb.Status{Code: int32(codes.OK)}}, true
return nil, true
}
if se, ok := err.(interface {
GRPCStatus() *Status
@ -206,7 +206,7 @@ func Code(err error) codes.Code {
func FromContextError(err error) *Status {
switch err {
case nil:
return New(codes.OK, "")
return nil
case context.DeadlineExceeded:
return New(codes.DeadlineExceeded, err.Error())
case context.Canceled: