summaryrefslogtreecommitdiff
path: root/vendor/github.com/vmihailenco/msgpack/v5/decode_slice.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-01-15 14:08:07 +0100
committerLibravatar GitHub <noreply@github.com>2024-01-15 14:08:07 +0100
commit6433a505820cfeb43990a3453a0ed8b24e432b7d (patch)
tree3f968a63d6a77991df95fde88ee0f08727f26eb6 /vendor/github.com/vmihailenco/msgpack/v5/decode_slice.go
parent[chore]: Bump github.com/tdewolff/minify/v2 from 2.20.12 to 2.20.14 (#2530) (diff)
downloadgotosocial-6433a505820cfeb43990a3453a0ed8b24e432b7d.tar.xz
[chore] update bun + extras v1.1.16 -> v1.1.17 (#2534)
Diffstat (limited to 'vendor/github.com/vmihailenco/msgpack/v5/decode_slice.go')
-rw-r--r--vendor/github.com/vmihailenco/msgpack/v5/decode_slice.go23
1 files changed, 15 insertions, 8 deletions
diff --git a/vendor/github.com/vmihailenco/msgpack/v5/decode_slice.go b/vendor/github.com/vmihailenco/msgpack/v5/decode_slice.go
index db6f7c547..9c155f2ba 100644
--- a/vendor/github.com/vmihailenco/msgpack/v5/decode_slice.go
+++ b/vendor/github.com/vmihailenco/msgpack/v5/decode_slice.go
@@ -49,7 +49,7 @@ func (d *Decoder) decodeStringSlicePtr(ptr *[]string) error {
return nil
}
- ss := makeStrings(*ptr, n)
+ ss := makeStrings(*ptr, n, d.flags&disableAllocLimitFlag != 0)
for i := 0; i < n; i++ {
s, err := d.DecodeString()
if err != nil {
@@ -62,8 +62,8 @@ func (d *Decoder) decodeStringSlicePtr(ptr *[]string) error {
return nil
}
-func makeStrings(s []string, n int) []string {
- if n > sliceAllocLimit {
+func makeStrings(s []string, n int, noLimit bool) []string {
+ if !noLimit && n > sliceAllocLimit {
n = sliceAllocLimit
}
@@ -101,10 +101,17 @@ func decodeSliceValue(d *Decoder, v reflect.Value) error {
v.Set(v.Slice(0, v.Cap()))
}
+ noLimit := d.flags&disableAllocLimitFlag != 1
+
+ if noLimit && n > v.Len() {
+ v.Set(growSliceValue(v, n, noLimit))
+ }
+
for i := 0; i < n; i++ {
- if i >= v.Len() {
- v.Set(growSliceValue(v, n))
+ if !noLimit && i >= v.Len() {
+ v.Set(growSliceValue(v, n, noLimit))
}
+
elem := v.Index(i)
if err := d.DecodeValue(elem); err != nil {
return err
@@ -114,9 +121,9 @@ func decodeSliceValue(d *Decoder, v reflect.Value) error {
return nil
}
-func growSliceValue(v reflect.Value, n int) reflect.Value {
+func growSliceValue(v reflect.Value, n int, noLimit bool) reflect.Value {
diff := n - v.Len()
- if diff > sliceAllocLimit {
+ if !noLimit && diff > sliceAllocLimit {
diff = sliceAllocLimit
}
v = reflect.AppendSlice(v, reflect.MakeSlice(v.Type(), diff, diff))
@@ -163,7 +170,7 @@ func (d *Decoder) decodeSlice(c byte) ([]interface{}, error) {
return nil, nil
}
- s := make([]interface{}, 0, min(n, sliceAllocLimit))
+ s := make([]interface{}, 0, n)
for i := 0; i < n; i++ {
v, err := d.decodeInterfaceCond()
if err != nil {