summaryrefslogtreecommitdiff
path: root/vendor/github.com/tetratelabs/wazero/internal/descriptor/table.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-10-06 20:53:03 +0000
committerLibravatar GitHub <noreply@github.com>2024-10-06 20:53:03 +0000
commitbd1866ad8a860e1b6d43c7fc988cf8c346f19f33 (patch)
tree6726f95b30b73baa4e5a7feed5c0b41bf46116db /vendor/github.com/tetratelabs/wazero/internal/descriptor/table.go
parent[chore/themes] Tweak colors on new themes (#3397) (diff)
downloadgotosocial-bd1866ad8a860e1b6d43c7fc988cf8c346f19f33.tar.xz
update go-ffmpreg to v0.3.1 (pulls in latest wazero too) (#3398)
Diffstat (limited to 'vendor/github.com/tetratelabs/wazero/internal/descriptor/table.go')
-rw-r--r--vendor/github.com/tetratelabs/wazero/internal/descriptor/table.go40
1 files changed, 15 insertions, 25 deletions
diff --git a/vendor/github.com/tetratelabs/wazero/internal/descriptor/table.go b/vendor/github.com/tetratelabs/wazero/internal/descriptor/table.go
index 03761e6ec..a20e19100 100644
--- a/vendor/github.com/tetratelabs/wazero/internal/descriptor/table.go
+++ b/vendor/github.com/tetratelabs/wazero/internal/descriptor/table.go
@@ -1,6 +1,9 @@
package descriptor
-import "math/bits"
+import (
+ "math/bits"
+ "slices"
+)
// Table is a data structure mapping 32 bit descriptor to items.
//
@@ -37,23 +40,13 @@ func (t *Table[Key, Item]) Len() (n int) {
return n
}
-// grow ensures that t has enough room for n items, potentially reallocating the
-// internal buffers if their capacity was too small to hold this many items.
+// grow grows the table by n * 64 items.
func (t *Table[Key, Item]) grow(n int) {
- // Round up to a multiple of 64 since this is the smallest increment due to
- // using 64 bits masks.
- n = (n*64 + 63) / 64
+ total := len(t.masks) + n
+ t.masks = slices.Grow(t.masks, n)[:total]
- if n > len(t.masks) {
- masks := make([]uint64, n)
- copy(masks, t.masks)
-
- items := make([]Item, n*64)
- copy(items, t.items)
-
- t.masks = masks
- t.items = items
- }
+ total = len(t.items) + n*64
+ t.items = slices.Grow(t.items, n*64)[:total]
}
// Insert inserts the given item to the table, returning the key that it is
@@ -78,13 +71,9 @@ insert:
}
}
+ // No free slot found, grow the table and retry.
offset = len(t.masks)
- n := 2 * len(t.masks)
- if n == 0 {
- n = 1
- }
-
- t.grow(n)
+ t.grow(1)
goto insert
}
@@ -109,10 +98,10 @@ func (t *Table[Key, Item]) InsertAt(item Item, key Key) bool {
if key < 0 {
return false
}
- if diff := int(key) - t.Len(); diff > 0 {
+ index := uint(key) / 64
+ if diff := int(index) - len(t.masks) + 1; diff > 0 {
t.grow(diff)
}
- index := uint(key) / 64
shift := uint(key) % 64
t.masks[index] |= 1 << shift
t.items[key] = item
@@ -124,7 +113,8 @@ func (t *Table[Key, Item]) Delete(key Key) {
if key < 0 { // invalid key
return
}
- if index, shift := key/64, key%64; int(index) < len(t.masks) {
+ if index := uint(key) / 64; int(index) < len(t.masks) {
+ shift := uint(key) % 64
mask := t.masks[index]
if (mask & (1 << shift)) != 0 {
var zero Item