Skip to content

Commit

Permalink
internal/socket: simplify nested if-blocks
Browse files Browse the repository at this point in the history
Change-Id: I9f5fa605d9dc4047f916d9adc998ed23a65839ed
Reviewed-on: https://go-review.googlesource.com/c/148357
Run-TryBot: Mikio Hara <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
mikioh committed Nov 8, 2018
1 parent 04ba8c8 commit 03003ca
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions internal/socket/sys_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 03003ca

Please sign in to comment.