mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-28 03:52:25 -05:00
- github.com/ncruces/go-sqlite3 - codeberg.org/gruf/go-mempool - codeberg.org/gruf/go-structr (changes related on the above) * - codeberg.org/gruf/go-mutexes (changes related on the above) * * this is largely just fiddling around with package internals in structr and mutexes to rely on changes in mempool, which added a new concurrency-safe pool Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4468 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package structr
|
|
|
|
import (
|
|
"os"
|
|
"unsafe"
|
|
|
|
"codeberg.org/gruf/go-mempool"
|
|
)
|
|
|
|
type indexed_item struct {
|
|
// linked list elem this item
|
|
// is stored in a main list.
|
|
elem list_elem
|
|
|
|
// cached data with type.
|
|
data interface{}
|
|
|
|
// indexed stores the indices
|
|
// this item is stored under.
|
|
indexed []*index_entry
|
|
}
|
|
|
|
var indexed_item_pool mempool.UnsafePool
|
|
|
|
// new_indexed_item returns a new prepared indexed_item.
|
|
func new_indexed_item() *indexed_item {
|
|
if ptr := indexed_item_pool.Get(); ptr != nil {
|
|
return (*indexed_item)(ptr)
|
|
}
|
|
item := new(indexed_item)
|
|
item.elem.data = unsafe.Pointer(item)
|
|
return item
|
|
}
|
|
|
|
// free_indexed_item releases the indexed_item.
|
|
func free_indexed_item(item *indexed_item) {
|
|
if len(item.indexed) > 0 ||
|
|
item.elem.next != nil ||
|
|
item.elem.prev != nil {
|
|
msg := assert("item not in use")
|
|
os.Stderr.WriteString(msg + "\n")
|
|
return
|
|
}
|
|
item.data = nil
|
|
ptr := unsafe.Pointer(item)
|
|
indexed_item_pool.Put(ptr)
|
|
}
|
|
|
|
// drop_index will drop the given index entry from item's indexed.
|
|
func (i *indexed_item) drop_index(entry *index_entry) {
|
|
for x := 0; x < len(i.indexed); x++ {
|
|
if i.indexed[x] != entry {
|
|
// Prof. Obiwan:
|
|
// this is not the index
|
|
// we are looking for.
|
|
continue
|
|
}
|
|
|
|
// Reslice index entries minus 'x'.
|
|
_ = copy(i.indexed[x:], i.indexed[x+1:])
|
|
i.indexed[len(i.indexed)-1] = nil
|
|
i.indexed = i.indexed[:len(i.indexed)-1]
|
|
break
|
|
}
|
|
}
|