Skip to content

Commit 7da1f7a

Browse files
committed
net: simplify nested if-blocks
Change-Id: I32e1829c955a48d8c4566430c13679e237bb0611 Reviewed-on: https://go-review.googlesource.com/c/148337 Run-TryBot: Mikio Hara <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 05a85f4 commit 7da1f7a

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/net/interface.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,13 @@ func (zc *ipv6ZoneCache) name(index int) string {
223223
zoneCache.RLock()
224224
name, ok := zoneCache.toName[index]
225225
zoneCache.RUnlock()
226-
if !ok {
227-
if !updated {
228-
zoneCache.update(nil, true)
229-
zoneCache.RLock()
230-
name, ok = zoneCache.toName[index]
231-
zoneCache.RUnlock()
232-
}
226+
if !ok && !updated {
227+
zoneCache.update(nil, true)
228+
zoneCache.RLock()
229+
name, ok = zoneCache.toName[index]
230+
zoneCache.RUnlock()
233231
}
234-
if !ok {
232+
if !ok { // last resort
235233
name = uitoa(uint(index))
236234
}
237235
return name
@@ -245,15 +243,13 @@ func (zc *ipv6ZoneCache) index(name string) int {
245243
zoneCache.RLock()
246244
index, ok := zoneCache.toIndex[name]
247245
zoneCache.RUnlock()
248-
if !ok {
249-
if !updated {
250-
zoneCache.update(nil, true)
251-
zoneCache.RLock()
252-
index, ok = zoneCache.toIndex[name]
253-
zoneCache.RUnlock()
254-
}
246+
if !ok && !updated {
247+
zoneCache.update(nil, true)
248+
zoneCache.RLock()
249+
index, ok = zoneCache.toIndex[name]
250+
zoneCache.RUnlock()
255251
}
256-
if !ok {
252+
if !ok { // last resort
257253
index, _, _ = dtoi(name)
258254
}
259255
return index

0 commit comments

Comments
 (0)