mirror of https://github.com/grpc/grpc-go.git
status: avoid allocations when returning an OK status (#2929)
This commit is contained in:
parent
decb43806d
commit
5da5b1f225
|
@ -132,7 +132,7 @@ func FromProto(s *spb.Status) *Status {
|
||||||
// Status is returned with codes.Unknown and the original error message.
|
// Status is returned with codes.Unknown and the original error message.
|
||||||
func FromError(err error) (s *Status, ok bool) {
|
func FromError(err error) (s *Status, ok bool) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return &Status{s: &spb.Status{Code: int32(codes.OK)}}, true
|
return nil, true
|
||||||
}
|
}
|
||||||
if se, ok := err.(interface {
|
if se, ok := err.(interface {
|
||||||
GRPCStatus() *Status
|
GRPCStatus() *Status
|
||||||
|
@ -206,7 +206,7 @@ func Code(err error) codes.Code {
|
||||||
func FromContextError(err error) *Status {
|
func FromContextError(err error) *Status {
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
return New(codes.OK, "")
|
return nil
|
||||||
case context.DeadlineExceeded:
|
case context.DeadlineExceeded:
|
||||||
return New(codes.DeadlineExceeded, err.Error())
|
return New(codes.DeadlineExceeded, err.Error())
|
||||||
case context.Canceled:
|
case context.Canceled:
|
||||||
|
|
Loading…
Reference in New Issue