update gruf / {go-cache, go-maps, go-kv} (#3361)

This commit is contained in:
kim 2024-09-27 10:26:50 +00:00 committed by GitHub
commit 2f582e2e33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 31 additions and 36 deletions

View file

@ -9,9 +9,3 @@ A `cache.Cache{}` implementation with much more of the inner workings exposed. D
## ttl
A `cache.TTLCache{}` implementation with much more of the inner workings exposed. Designed to be used as a base for your own customizations, or used as-is.
## result
`result.Cache` is an example of a more complex cache implementation using `ttl.Cache{}` as its underpinning.
It provides caching specifically of loadable struct types, with automatic keying by multiple different field members and caching of negative (error) values. All useful when wrapping, for example, a database.

View file

@ -197,7 +197,8 @@ func (f format) AppendBytes(b []byte) {
// Quoted only if spaces/requires escaping
case f.Key():
f.AppendStringSafe(b2s(b))
s := byteutil.B2S(b)
f.AppendStringSafe(s)
// Append as separate ASCII quoted bytes in slice
case f.Verbose():
@ -214,7 +215,8 @@ func (f format) AppendBytes(b []byte) {
// Quoted only if spaces/requires escaping
case f.Value():
f.AppendStringSafe(b2s(b))
s := byteutil.B2S(b)
f.AppendStringSafe(s)
// Append as raw bytes
default:

View file

@ -98,8 +98,3 @@ func isNil(i interface{}) bool {
type eface struct{ _type, data unsafe.Pointer } //nolint
return (*(*eface)(unsafe.Pointer(&i))).data == nil //nolint
}
// b2s converts a byteslice to string without allocation.
func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

View file

@ -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) {}
}

12
vendor/modules.txt vendored
View file

@ -7,8 +7,8 @@ codeberg.org/gruf/go-bytesize
# codeberg.org/gruf/go-byteutil v1.3.0
## explicit; go 1.20
codeberg.org/gruf/go-byteutil
# codeberg.org/gruf/go-cache/v3 v3.5.7
## explicit; go 1.19
# codeberg.org/gruf/go-cache/v3 v3.6.1
## explicit; go 1.20
codeberg.org/gruf/go-cache/v3
codeberg.org/gruf/go-cache/v3/simple
codeberg.org/gruf/go-cache/v3/ttl
@ -31,8 +31,8 @@ codeberg.org/gruf/go-ffmpreg/embed/ffprobe
# codeberg.org/gruf/go-iotools v0.0.0-20240710125620-934ae9c654cf
## explicit; go 1.21
codeberg.org/gruf/go-iotools
# codeberg.org/gruf/go-kv v1.6.4
## explicit; go 1.19
# codeberg.org/gruf/go-kv v1.6.5
## explicit; go 1.20
codeberg.org/gruf/go-kv
codeberg.org/gruf/go-kv/format
# codeberg.org/gruf/go-list v0.0.0-20240425093752-494db03d641f
@ -41,8 +41,8 @@ codeberg.org/gruf/go-list
# codeberg.org/gruf/go-mangler v1.4.1
## explicit; go 1.19
codeberg.org/gruf/go-mangler
# codeberg.org/gruf/go-maps v1.0.3
## explicit; go 1.19
# codeberg.org/gruf/go-maps v1.0.4
## explicit; go 1.20
codeberg.org/gruf/go-maps
# codeberg.org/gruf/go-mempool v0.0.0-20240507125005-cef10d64a760
## explicit; go 1.22.2