summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-maps/common.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-09-27 10:26:50 +0000
committerLibravatar GitHub <noreply@github.com>2024-09-27 10:26:50 +0000
commit2f582e2e33b2bae06e136bd2a547a934a6700074 (patch)
treeade1642ba12d27ae8f38b7e88b170f5491c5e0fc /vendor/codeberg.org/gruf/go-maps/common.go
parent[chore] bump go-byteutil v1.2.0 -> v1.3.0 (#3356) (diff)
downloadgotosocial-2f582e2e33b2bae06e136bd2a547a934a6700074.tar.xz
update gruf / {go-cache, go-maps, go-kv} (#3361)
Diffstat (limited to 'vendor/codeberg.org/gruf/go-maps/common.go')
-rw-r--r--vendor/codeberg.org/gruf/go-maps/common.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/vendor/codeberg.org/gruf/go-maps/common.go b/vendor/codeberg.org/gruf/go-maps/common.go
index f5877ee3a..0c92b41a2 100644
--- a/vendor/codeberg.org/gruf/go-maps/common.go
+++ b/vendor/codeberg.org/gruf/go-maps/common.go
@@ -17,7 +17,7 @@ type ordered[K comparable, V any] struct {
}
// write_check panics if map is not in a safe-state to write to.
-func (m ordered[K, V]) write_check() {
+func (m *ordered[K, V]) write_check() {
if m.rnly {
panic("map write during read loop")
}
@@ -54,15 +54,17 @@ func (m *ordered[K, V]) Delete(key K) bool {
// Range passes given function over the requested range of the map.
func (m *ordered[K, V]) Range(start, length int, fn func(int, K, V)) {
+ // Nil check
+ if fn == nil {
+ panic("nil func")
+ }
+
// Disallow writes
m.rnly = true
defer func() {
m.rnly = false
}()
- // Nil check
- _ = fn
-
switch end := start + length; {
// No loop to iterate
case length == 0:
@@ -104,15 +106,17 @@ func (m *ordered[K, V]) Range(start, length int, fn func(int, K, V)) {
// RangeIf passes given function over the requested range of the map. Returns early on 'fn' -> false.
func (m *ordered[K, V]) RangeIf(start, length int, fn func(int, K, V) bool) {
+ // Nil check
+ if fn == nil {
+ panic("nil func")
+ }
+
// Disallow writes
m.rnly = true
defer func() {
m.rnly = false
}()
- // Nil check
- _ = fn
-
switch end := start + length; {
// No loop to iterate
case length == 0:
@@ -163,8 +167,8 @@ func (m *ordered[K, V]) Truncate(sz int, fn func(K, V)) {
panic("index out of bounds")
}
+ // Nil check
if fn == nil {
- // move nil check out of loop
fn = func(K, V) {}
}