Bläddra i källkod

internal/socket: simplify nested if-blocks

Change-Id: I9f5fa605d9dc4047f916d9adc998ed23a65839ed
Reviewed-on: https://go-review.googlesource.com/c/148357
Run-TryBot: Mikio Hara <mikioh.public.networking@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Mikio Hara 7 år sedan
förälder
incheckning
03003ca0c8
1 ändrade filer med 12 tillägg och 16 borttagningar
  1. 12 16
      internal/socket/sys_posix.go

+ 12 - 16
internal/socket/sys_posix.go

@@ -154,15 +154,13 @@ func (zc *ipv6ZoneCache) name(zone int) string {
 	zoneCache.RLock()
 	name, ok := zoneCache.toName[zone]
 	zoneCache.RUnlock()
-	if !ok {
-		if !updated {
-			zoneCache.update(nil, true)
-			zoneCache.RLock()
-			name, ok = zoneCache.toName[zone]
-			zoneCache.RUnlock()
-		}
+	if !ok && !updated {
+		zoneCache.update(nil, true)
+		zoneCache.RLock()
+		name, ok = zoneCache.toName[zone]
+		zoneCache.RUnlock()
 	}
-	if !ok {
+	if !ok { // last resort
 		name = strconv.Itoa(zone)
 	}
 	return name
@@ -173,15 +171,13 @@ func (zc *ipv6ZoneCache) index(zone string) int {
 	zoneCache.RLock()
 	index, ok := zoneCache.toIndex[zone]
 	zoneCache.RUnlock()
-	if !ok {
-		if !updated {
-			zoneCache.update(nil, true)
-			zoneCache.RLock()
-			index, ok = zoneCache.toIndex[zone]
-			zoneCache.RUnlock()
-		}
+	if !ok && !updated {
+		zoneCache.update(nil, true)
+		zoneCache.RLock()
+		index, ok = zoneCache.toIndex[zone]
+		zoneCache.RUnlock()
 	}
-	if !ok {
+	if !ok { // last resort
 		index, _ = strconv.Atoi(zone)
 	}
 	return index