Skip to content

Commit

Permalink
Fix empty string checks. (#5390)
Browse files Browse the repository at this point in the history
There's no need to call the len function when checking for an empty
string.
  • Loading branch information
martinmr committed May 7, 2020
1 parent a6df573 commit 6cb3691
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dgraph/cmd/zero/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions dgraph/cmd/zero/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion posting/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6cb3691

Please sign in to comment.