]> Cypherpunks.ru repositories - nncp.git/commitdiff
Map keys existence check simplification
authorSergey Matveev <stargrave@stargrave.org>
Fri, 9 Jul 2021 12:04:06 +0000 (15:04 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 9 Jul 2021 12:21:26 +0000 (15:21 +0300)
src/progress.go
src/sp.go
src/toss.go

index 0c2f0ee2c99f7cd874edd56fbded6e815bbdf8d2..5ebc72bdb20b2e16df5ba53ed33bf0669f5a13b5 100644 (file)
@@ -132,9 +132,9 @@ func Progress(prefix string, les LEs) {
                }
        }
        progressBarsLock.RLock()
-       pb, exists := progressBars[pkt]
+       pb := progressBars[pkt]
        progressBarsLock.RUnlock()
-       if !exists {
+       if pb == nil {
                progressBarsLock.Lock()
                pb = ProgressBarNew(size, fullsize)
                progressBars[pkt] = pb
@@ -156,8 +156,8 @@ func Progress(prefix string, les LEs) {
 
 func ProgressKill(pkt string) {
        progressBarsLock.Lock()
-       pb, exists := progressBars[pkt]
-       if exists {
+       pb := progressBars[pkt]
+       if pb != nil {
                pb.Kill()
                delete(progressBars, pkt)
        }
index 5840bd15c794b7586a26098d6c4cdc750a9d0f7c..5937d35e30084d5480adedf273afd2e209aa1ddf 100644 (file)
--- a/src/sp.go
+++ b/src/sp.go
@@ -1324,9 +1324,9 @@ func (state *SPState) ProcessSP(payload []byte) ([][]byte, error) {
                        }
                        fullsize := int64(0)
                        state.RLock()
-                       infoTheir, ok := state.infosTheir[*file.Hash]
+                       infoTheir := state.infosTheir[*file.Hash]
                        state.RUnlock()
-                       if !ok {
+                       if infoTheir == nil {
                                state.Ctx.LogE("sp-file-open", lesp, err, func(les LEs) string {
                                        return logMsg(les) + ": unknown file"
                                })
index dc5573bd675527fb63084b5b2be2972dfbee130c..21d3007e74ecd263c86030dbc1bdf1f9e06998a4 100644 (file)
@@ -120,8 +120,8 @@ func jobProcess(
                }
                argsStr := strings.Join(append([]string{handle}, args...), " ")
                les = append(les, LE{"Type", "exec"}, LE{"Dst", argsStr})
-               cmdline, exists := sender.Exec[handle]
-               if !exists || len(cmdline) == 0 {
+               cmdline := sender.Exec[handle]
+               if len(cmdline) == 0 {
                        err = errors.New("No handle found")
                        ctx.LogE(
                                "rx-no-handle", les, err,
@@ -165,11 +165,11 @@ func jobProcess(
                                return err
                        }
                        if len(sendmail) > 0 && ctx.NotifyExec != nil {
-                               notify, exists := ctx.NotifyExec[sender.Name+"."+handle]
-                               if !exists {
-                                       notify, exists = ctx.NotifyExec["*."+handle]
+                               notify := ctx.NotifyExec[sender.Name+"."+handle]
+                               if notify == nil {
+                                       notify = ctx.NotifyExec["*."+handle]
                                }
-                               if exists {
+                               if notify != nil {
                                        cmd := exec.Command(
                                                sendmail[0],
                                                append(sendmail[1:], notify.To)...,