mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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 😇 --------- Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
This commit is contained in:
78
vendor/codeberg.org/gruf/go-structr/list.go
generated
vendored
78
vendor/codeberg.org/gruf/go-structr/list.go
generated
vendored
@ -5,8 +5,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var list_pool sync.Pool
|
||||
|
||||
// elem represents an elem
|
||||
// in a doubly-linked list.
|
||||
type list_elem struct {
|
||||
@ -28,28 +26,28 @@ type list struct {
|
||||
len int
|
||||
}
|
||||
|
||||
func list_acquire() *list {
|
||||
// Acquire from pool.
|
||||
var list_pool sync.Pool
|
||||
|
||||
// new_list returns a new prepared list.
|
||||
func new_list() *list {
|
||||
v := list_pool.Get()
|
||||
if v == nil {
|
||||
v = new(list)
|
||||
}
|
||||
|
||||
// Cast list value.
|
||||
return v.(*list)
|
||||
list := v.(*list)
|
||||
return list
|
||||
}
|
||||
|
||||
func list_release(l *list) {
|
||||
// Reset list.
|
||||
l.head = nil
|
||||
l.tail = nil
|
||||
l.len = 0
|
||||
|
||||
// Release to pool.
|
||||
list_pool.Put(l)
|
||||
// free_list releases the list.
|
||||
func free_list(list *list) {
|
||||
list.head = nil
|
||||
list.tail = nil
|
||||
list.len = 0
|
||||
list_pool.Put(list)
|
||||
}
|
||||
|
||||
func list_push_front(l *list, elem *list_elem) {
|
||||
// push_front will push the given elem to front (head) of list.
|
||||
func (l *list) push_front(elem *list_elem) {
|
||||
if l.len == 0 {
|
||||
// Set new tail + head
|
||||
l.head = elem
|
||||
@ -77,12 +75,49 @@ func list_push_front(l *list, elem *list_elem) {
|
||||
l.len++
|
||||
}
|
||||
|
||||
func list_move_front(l *list, elem *list_elem) {
|
||||
list_remove(l, elem)
|
||||
list_push_front(l, elem)
|
||||
// push_back will push the given elem to back (tail) of list.
|
||||
func (l *list) push_back(elem *list_elem) {
|
||||
if l.len == 0 {
|
||||
// Set new tail + head
|
||||
l.head = elem
|
||||
l.tail = elem
|
||||
|
||||
// Link elem to itself
|
||||
elem.next = elem
|
||||
elem.prev = elem
|
||||
} else {
|
||||
oldTail := l.tail
|
||||
|
||||
// Link to old tail
|
||||
elem.prev = oldTail
|
||||
oldTail.next = elem
|
||||
|
||||
// Link up to head
|
||||
elem.next = l.head
|
||||
l.head.prev = elem
|
||||
|
||||
// Set new tail
|
||||
l.tail = elem
|
||||
}
|
||||
|
||||
// Incr count
|
||||
l.len++
|
||||
}
|
||||
|
||||
func list_remove(l *list, elem *list_elem) {
|
||||
// move_front will move given elem to front (head) of list.
|
||||
func (l *list) move_front(elem *list_elem) {
|
||||
l.remove(elem)
|
||||
l.push_front(elem)
|
||||
}
|
||||
|
||||
// move_back will move given elem to back (tail) of list.
|
||||
func (l *list) move_back(elem *list_elem) {
|
||||
l.remove(elem)
|
||||
l.push_back(elem)
|
||||
}
|
||||
|
||||
// remove will remove given elem from list.
|
||||
func (l *list) remove(elem *list_elem) {
|
||||
if l.len <= 1 {
|
||||
// Drop elem's links
|
||||
elem.next = nil
|
||||
@ -121,7 +156,8 @@ func list_remove(l *list, elem *list_elem) {
|
||||
l.len--
|
||||
}
|
||||
|
||||
func list_rangefn(l *list, fn func(*list_elem)) {
|
||||
// rangefn will range all elems in list, passing each to fn.
|
||||
func (l *list) rangefn(fn func(*list_elem)) {
|
||||
if fn == nil {
|
||||
panic("nil fn")
|
||||
}
|
||||
|
Reference in New Issue
Block a user