From 6cb3691bb7916141f21147051c9812110d1f196e Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Thu, 7 May 2020 12:32:55 -0700 Subject: [PATCH] Fix empty string checks. (#5390) There's no need to call the len function when checking for an empty string. --- dgraph/cmd/zero/raft.go | 2 +- dgraph/cmd/zero/run.go | 2 +- dgraph/cmd/zero/zero.go | 4 ++-- posting/index.go | 2 +- query/query.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dgraph/cmd/zero/raft.go b/dgraph/cmd/zero/raft.go index aab40c4d55a..4d5db5ed4df 100644 --- a/dgraph/cmd/zero/raft.go +++ b/dgraph/cmd/zero/raft.go @@ -303,7 +303,7 @@ func (n *node) applyProposal(e raftpb.Entry) (string, error) { if err := p.Unmarshal(e.Data); err != nil { return p.Key, err } - if len(p.Key) == 0 { + if p.Key == "" { return p.Key, errInvalidProposal } span := otrace.FromContext(n.Proposals.Ctx(p.Key)) diff --git a/dgraph/cmd/zero/run.go b/dgraph/cmd/zero/run.go index d99a16ac5d1..3acb2854dd6 100644 --- a/dgraph/cmd/zero/run.go +++ b/dgraph/cmd/zero/run.go @@ -211,7 +211,7 @@ func run() { if opts.bindall { addr = "0.0.0.0" } - if len(opts.myAddr) == 0 { + if opts.myAddr == "" { opts.myAddr = fmt.Sprintf("localhost:%d", x.PortZeroGrpc+opts.portOffset) } diff --git a/dgraph/cmd/zero/zero.go b/dgraph/cmd/zero/zero.go index 73c032cd30f..f2cd7d8d021 100644 --- a/dgraph/cmd/zero/zero.go +++ b/dgraph/cmd/zero/zero.go @@ -434,7 +434,7 @@ func (s *Server) Connect(ctx context.Context, } return cs, err } - if len(m.Addr) == 0 { + if m.Addr == "" { return &emptyConnectionState, errors.Errorf("NO_ADDR: No address provided: %+v", m) } @@ -568,7 +568,7 @@ func (s *Server) ShouldServe( ctx, span := otrace.StartSpan(ctx, "Zero.ShouldServe") defer span.End() - if len(tablet.Predicate) == 0 { + if tablet.Predicate == "" { return resp, errors.Errorf("Tablet predicate is empty in %+v", tablet) } if tablet.GroupId == 0 && !tablet.ReadOnly { diff --git a/posting/index.go b/posting/index.go index 41f04339da2..66e8da2c86b 100644 --- a/posting/index.go +++ b/posting/index.go @@ -403,7 +403,7 @@ func (txn *Txn) addMutationHelper(ctx context.Context, l *List, doUpdateIndex bo // AddMutationWithIndex is addMutation with support for indexing. It also // supports reverse edges. func (l *List) AddMutationWithIndex(ctx context.Context, edge *pb.DirectedEdge, txn *Txn) error { - if len(edge.Attr) == 0 { + if edge.Attr == "" { return errors.Errorf("Predicate cannot be empty for edge with subject: [%v], object: [%v]"+ " and value: [%v]", edge.Entity, edge.ValueId, edge.Value) } diff --git a/query/query.go b/query/query.go index f7d2ef845f1..739220047ae 100644 --- a/query/query.go +++ b/query/query.go @@ -1961,7 +1961,7 @@ func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error) { return sg.DestUIDs.Uids[i] < sg.DestUIDs.Uids[j] }) } - case len(sg.Attr) == 0: + case sg.Attr == "": // This is when we have uid function in children. if sg.SrcFunc != nil && sg.SrcFunc.Name == "uid" { // If its a uid() filter, we just have to intersect the SrcUIDs with DestUIDs