diff options
author | 2024-04-02 11:03:40 +0100 | |
---|---|---|
committer | 2024-04-02 12:03:40 +0200 | |
commit | adf345f1ec0cb76a0df94a4505143d891659cba9 (patch) | |
tree | e0cca289c0a50f30191d4b65a2c336704570e470 /vendor/codeberg.org/gruf/go-structr/result.go | |
parent | [feature] Option to hide followers/following (#2788) (diff) | |
download | gotosocial-adf345f1ec0cb76a0df94a4505143d891659cba9.tar.xz |
[chore] bump go structr cache version -> v0.6.0 (#2773)
* update go-structr library -> v0.6.0, add necessary wrapping types + code changes to support these changes
* update readme with go-structr package changes
* improved wrapping of the SliceCache type
* add code comments for the cache wrapper types
* remove test.out :innocent:
---------
Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-structr/result.go')
-rw-r--r-- | vendor/codeberg.org/gruf/go-structr/result.go | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/vendor/codeberg.org/gruf/go-structr/result.go b/vendor/codeberg.org/gruf/go-structr/result.go deleted file mode 100644 index 08d3ad013..000000000 --- a/vendor/codeberg.org/gruf/go-structr/result.go +++ /dev/null @@ -1,78 +0,0 @@ -package structr - -import ( - "sync" - "unsafe" -) - -var result_pool sync.Pool - -type result struct { - // linked list elem this result is - // stored under in Cache.lruList. - elem list_elem - - // indexed stores the indices - // this result is stored under. - indexed []*index_entry - - // cached data (we maintain - // the type data here using - // an interface as any one - // instance can be T / error). - data interface{} -} - -func result_acquire[T any](c *Cache[T]) *result { - // Acquire from pool. - v := result_pool.Get() - if v == nil { - v = new(result) - } - - // Cast result value. - res := v.(*result) - - // Push result elem to front of LRU list. - list_push_front(&c.lruList, &res.elem) - res.elem.data = unsafe.Pointer(res) - - return res -} - -func result_release[T any](c *Cache[T], res *result) { - // Remove result elem from LRU list. - list_remove(&c.lruList, &res.elem) - res.elem.data = nil - - // Reset all result fields. - res.indexed = res.indexed[:0] - res.data = nil - - // Release to pool. - result_pool.Put(res) -} - -func result_drop_index[T any](res *result, index *Index[T]) { - for i := 0; i < len(res.indexed); i++ { - - if res.indexed[i].index != unsafe.Pointer(index) { - // Prof. Obiwan: - // this is not the index - // we are looking for. - continue - } - - // Get index entry ptr. - entry := res.indexed[i] - - // Move all index entries down + reslice. - copy(res.indexed[i:], res.indexed[i+1:]) - res.indexed = res.indexed[:len(res.indexed)-1] - - // Release to memory pool. - index_entry_release(entry) - - return - } -} |