Skip to content

Commit 3205d65

Browse files
committed
used naked returns
1 parent 86df57f commit 3205d65

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ linters:
2323
- stylecheck
2424
- usestdlibvars
2525
- wastedassign
26-
- nakedret
26+
# - nakedret
2727
#
2828
# - gosec
2929
# - dupl

node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (n *node[V]) lpmGet(idx uint) (baseIdx uint, val V, ok bool) {
353353
}
354354

355355
// not found (on this level)
356-
return 0, val, false
356+
return
357357
}
358358

359359
// lpmTest, true if idx has a (any) longest-prefix-match in node.

table.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (t *Table[V]) Update(pfx netip.Prefix, cb func(val V, ok bool) V) (newVal V
136136
var zero V
137137

138138
if !pfx.IsValid() {
139-
return zero
139+
return
140140
}
141141

142142
// canonicalize prefix
@@ -239,7 +239,7 @@ func (t *Table[V]) GetAndDelete(pfx netip.Prefix) (val V, ok bool) {
239239

240240
func (t *Table[V]) getAndDelete(pfx netip.Prefix) (val V, exists bool) {
241241
if !pfx.IsValid() {
242-
return val, false
242+
return
243243
}
244244

245245
// canonicalize prefix
@@ -254,16 +254,13 @@ func (t *Table[V]) getAndDelete(pfx netip.Prefix) (val V, exists bool) {
254254

255255
n := t.rootNodeByVersion(is4)
256256

257-
// record path to deleted node
258-
// needed to purge and/or path compress nodes after deletion
257+
// record the nodes on the path to the deleted node, needed to purge
258+
// and/or path compress nodes after the deletion of a prefix
259259
stack := [maxTreeDepth]*node[V]{}
260260

261261
// find the trie node
262262
for depth, octet := range octets {
263263
depth = depth & 0xf // BCE, Delete must be fast
264-
if depth > maxDepth {
265-
break
266-
}
267264

268265
// push current node on stack for path recording
269266
stack[depth] = n
@@ -272,7 +269,7 @@ func (t *Table[V]) getAndDelete(pfx netip.Prefix) (val V, exists bool) {
272269
// try to delete prefix in trie node
273270
val, exists = n.prefixes.DeleteAt(art.PfxToIdx(octet, lastBits))
274271
if !exists {
275-
return val, false
272+
return
276273
}
277274

278275
t.sizeUpdate(is4, -1)
@@ -282,7 +279,7 @@ func (t *Table[V]) getAndDelete(pfx netip.Prefix) (val V, exists bool) {
282279

283280
addr := uint(octet)
284281
if !n.children.Test(addr) {
285-
return val, false
282+
return
286283
}
287284
kid := n.children.MustGet(addr)
288285

@@ -295,7 +292,7 @@ func (t *Table[V]) getAndDelete(pfx netip.Prefix) (val V, exists bool) {
295292
case *fringeNode[V]:
296293
// if pfx is no fringe at this depth, fast exit
297294
if !isFringe(depth, bits) {
298-
return val, false
295+
return
299296
}
300297

301298
// pfx is fringe at depth, delete fringe
@@ -309,7 +306,7 @@ func (t *Table[V]) getAndDelete(pfx netip.Prefix) (val V, exists bool) {
309306
case *leafNode[V]:
310307
// Attention: pfx must be masked to be comparable!
311308
if kid.prefix != pfx {
312-
return val, false
309+
return
313310
}
314311

315312
// prefix is equal leaf, delete leaf
@@ -325,16 +322,14 @@ func (t *Table[V]) getAndDelete(pfx netip.Prefix) (val V, exists bool) {
325322
}
326323
}
327324

328-
panic("unreachable")
325+
return
329326
}
330327

331328
// Get returns the associated payload for prefix and true, or false if
332329
// prefix is not set in the routing table.
333330
func (t *Table[V]) Get(pfx netip.Prefix) (val V, ok bool) {
334-
var zero V
335-
336331
if !pfx.IsValid() {
337-
return zero, false
332+
return
338333
}
339334

340335
// canonicalize the prefix
@@ -359,7 +354,7 @@ func (t *Table[V]) Get(pfx netip.Prefix) (val V, ok bool) {
359354

360355
addr := uint(octet)
361356
if !n.children.Test(addr) {
362-
return zero, false
357+
return
363358
}
364359
kid := n.children.MustGet(addr)
365360

@@ -374,20 +369,21 @@ func (t *Table[V]) Get(pfx netip.Prefix) (val V, ok bool) {
374369
if isFringe(depth, bits) {
375370
return kid.value, true
376371
}
377-
return zero, false
372+
return
378373

379374
case *leafNode[V]:
380375
// reached a path compressed prefix, stop traversing
381376
if kid.prefix == pfx {
382377
return kid.value, true
383378
}
384-
return zero, false
379+
return
385380

386381
default:
387382
panic("logic error, wrong node type")
388383
}
389384
}
390-
return zero, false
385+
386+
panic("unreachable")
391387
}
392388

393389
// Contains does a route lookup for IP and
@@ -440,7 +436,7 @@ func (t *Table[V]) Contains(ip netip.Addr) bool {
440436
// returns the associated value and true, or false if no route matched.
441437
func (t *Table[V]) Lookup(ip netip.Addr) (val V, ok bool) {
442438
if !ip.IsValid() {
443-
return val, false
439+
return
444440
}
445441

446442
is4 := ip.Is4()
@@ -513,7 +509,7 @@ LOOP:
513509
}
514510
}
515511

516-
return val, false
512+
return
517513
}
518514

519515
// LookupPrefix does a route lookup (longest prefix match) for pfx and
@@ -537,7 +533,7 @@ func (t *Table[V]) LookupPrefixLPM(pfx netip.Prefix) (lpmPfx netip.Prefix, val V
537533

538534
func (t *Table[V]) lookupPrefixLPM(pfx netip.Prefix, withLPM bool) (lpmPfx netip.Prefix, val V, ok bool) {
539535
if !pfx.IsValid() {
540-
return lpmPfx, val, false
536+
return
541537
}
542538

543539
// canonicalize the prefix
@@ -654,7 +650,7 @@ LOOP:
654650
}
655651
}
656652

657-
return lpmPfx, val, false
653+
return
658654
}
659655

660656
// Supernets returns an iterator over all CIDRs covering pfx.

0 commit comments

Comments
 (0)