summaryrefslogtreecommitdiff
path: root/lib/containers
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 23:07:13 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 23:07:13 -0700
commit9eef4dd91c36b60a2d5a68141f1d0c07e25be129 (patch)
tree4754b06e54d7e888e636472007fc1bc87aa72d72 /lib/containers
parent0134f07a4b97a455557277b2c89e0ee5ad6b2e62 (diff)
parent50a8b3eac39caccedb3ec34c150ba37e40cc2da5 (diff)
Merge branch 'lukeshu/fast-json'
Diffstat (limited to 'lib/containers')
-rw-r--r--lib/containers/set.go4
-rw-r--r--lib/containers/syncmap.go53
2 files changed, 2 insertions, 55 deletions
diff --git a/lib/containers/set.go b/lib/containers/set.go
index 4fc8aad..b2af494 100644
--- a/lib/containers/set.go
+++ b/lib/containers/set.go
@@ -71,7 +71,7 @@ func (o Set[T]) EncodeJSON(w io.Writer) error {
return less(keys[i], keys[j])
})
- return lowmemjson.Encode(w, keys)
+ return lowmemjson.NewEncoder(w).Encode(keys)
}
func (o *Set[T]) DecodeJSON(r io.RuneScanner) error {
@@ -87,7 +87,7 @@ func (o *Set[T]) DecodeJSON(r io.RuneScanner) error {
*o = Set[T]{}
return lowmemjson.DecodeArray(r, func(r io.RuneScanner) error {
var val T
- if err := lowmemjson.Decode(r, &val); err != nil {
+ if err := lowmemjson.NewDecoder(r).Decode(&val); err != nil {
return err
}
(*o)[val] = struct{}{}
diff --git a/lib/containers/syncmap.go b/lib/containers/syncmap.go
deleted file mode 100644
index 74da4b3..0000000
--- a/lib/containers/syncmap.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
-//
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-package containers
-
-import (
- "sync"
-)
-
-type SyncMap[K comparable, V any] struct {
- inner sync.Map
-}
-
-func (m *SyncMap[K, V]) Delete(key K) {
- m.inner.Delete(key)
-}
-
-func (m *SyncMap[K, V]) Load(key K) (value V, ok bool) {
- _value, ok := m.inner.Load(key)
- if ok {
- //nolint:forcetypeassert // Typed wrapper around untyped lib.
- value = _value.(V)
- }
- return value, ok
-}
-
-func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool) {
- _value, ok := m.inner.LoadAndDelete(key)
- if ok {
- //nolint:forcetypeassert // Typed wrapper around untyped lib.
- value = _value.(V)
- }
- return value, ok
-}
-
-func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) {
- _actual, loaded := m.inner.LoadOrStore(key, value)
- //nolint:forcetypeassert // Typed wrapper around untyped lib.
- actual = _actual.(V)
- return actual, loaded
-}
-
-func (m *SyncMap[K, V]) Range(f func(key K, value V) bool) {
- m.inner.Range(func(key, value any) bool {
- //nolint:forcetypeassert // Typed wrapper around untyped lib.
- return f(key.(K), value.(V))
- })
-}
-
-func (m *SyncMap[K, V]) Store(key K, value V) {
- m.inner.Store(key, value)
-}