From 865b3aeaac8f165462796a7a5f8cf04ae7724d0f Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Sun, 11 Aug 2024 09:23:36 +0000 Subject: [bugfix] updated pinned counts on status delete (#3188) * include pinned status when incrementing / decrementing status counts * remove the pinned increment on status creation * code comments * microoptimize decr --- internal/util/math.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'internal/util/math.go') diff --git a/internal/util/math.go b/internal/util/math.go index e1850f772..f6e78fa1c 100644 --- a/internal/util/math.go +++ b/internal/util/math.go @@ -23,6 +23,15 @@ type Number interface { ~uintptr | ~float32 | ~float64 } +// Decr performs a safe decrement of +// n, clamping minimum value at zero. +func Decr[N Number](n N) N { + if n <= 0 { + return 0 + } + return n - 1 +} + // Div performs a safe division of // n1 and n2, checking for zero n2. In the // case of zero n2, zero is returned. -- cgit v1.2.3