summaryrefslogtreecommitdiff
path: root/vendor/github.com/ugorji/go/codec/helper.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-05-02 14:05:18 +0100
committerLibravatar GitHub <noreply@github.com>2022-05-02 15:05:18 +0200
commitb56dae8120d43b9acd3d3ed4d40100ffab7b972a (patch)
treed55d30589d8a8499ed3d5eecba163abc9fa78c27 /vendor/github.com/ugorji/go/codec/helper.go
parentadd extra indexes as a migration (#527) (diff)
downloadgotosocial-b56dae8120d43b9acd3d3ed4d40100ffab7b972a.tar.xz
[chore] Update all but bun libraries (#526)
* update all but bun libraries Signed-off-by: kim <grufwub@gmail.com> * remove my personal build script changes Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/github.com/ugorji/go/codec/helper.go')
-rw-r--r--vendor/github.com/ugorji/go/codec/helper.go43
1 files changed, 29 insertions, 14 deletions
diff --git a/vendor/github.com/ugorji/go/codec/helper.go b/vendor/github.com/ugorji/go/codec/helper.go
index 68025c5d8..dc485a5ef 100644
--- a/vendor/github.com/ugorji/go/codec/helper.go
+++ b/vendor/github.com/ugorji/go/codec/helper.go
@@ -943,13 +943,18 @@ func (x *basicHandleRuntimeState) setExt(rt reflect.Type, tag uint64, ext Ext) (
}
rtid := rt2id(rt)
+ // handle all natively supported type appropriately, so they cannot have an extension.
+ // However, we do not return an error for these, as we do not document that.
+ // Instead, we silently treat as a no-op, and return.
switch rtid {
- case timeTypId, rawTypId, rawExtTypId:
- // these are all natively supported type, so they cannot have an extension.
- // However, we do not return an error for these, as we do not document that.
- // Instead, we silently treat as a no-op, and return.
+ case rawTypId, rawExtTypId:
return
+ case timeTypId:
+ if x.timeBuiltin {
+ return
+ }
}
+
for i := range x.extHandle {
v := &x.extHandle[i]
if v.rtid == rtid {
@@ -1966,7 +1971,7 @@ func (ti *typeInfo) init(x []structFieldInfo, n int) {
// Handling flagCanTransient
//
// We support transient optimization if the kind of the type is
-// a number, bool, string, or slice.
+// a number, bool, string, or slice (of number/bool).
// In addition, we also support if the kind is struct or array,
// and the type does not contain any pointers recursively).
//
@@ -1976,15 +1981,20 @@ func (ti *typeInfo) init(x []structFieldInfo, n int) {
// when GC tries to follow a "transient" pointer which may become a non-pointer soon after.
//
-func isCanTransient(t reflect.Type, k reflect.Kind) (v bool) {
- var bs *bitset32
+func transientBitsetFlags() *bitset32 {
if transientValueHasStringSlice {
- bs = &numBoolStrSliceBitset
- } else {
- bs = &numBoolBitset
+ return &numBoolStrSliceBitset
}
+ return &numBoolBitset
+}
+
+func isCanTransient(t reflect.Type, k reflect.Kind) (v bool) {
+ var bs = transientBitsetFlags()
if bs.isset(byte(k)) {
v = true
+ } else if k == reflect.Slice {
+ elem := t.Elem()
+ v = numBoolBitset.isset(byte(elem.Kind()))
} else if k == reflect.Array {
elem := t.Elem()
v = isCanTransient(elem, elem.Kind())
@@ -2010,8 +2020,7 @@ func (ti *typeInfo) doSetFlagCanTransient() {
ti.flagCanTransient = true
}
if ti.flagCanTransient {
- // if ti kind is a num, bool, string or slice, then it is flagCanTransient
- if !numBoolStrSliceBitset.isset(ti.kind) {
+ if !transientBitsetFlags().isset(ti.kind) {
ti.flagCanTransient = isCanTransient(ti.rt, reflect.Kind(ti.kind))
}
}
@@ -2472,13 +2481,19 @@ func panicValToErr(h errDecorator, v interface{}, err *error) {
}
func usableByteSlice(bs []byte, slen int) (out []byte, changed bool) {
+ const maxCap = 1024 * 1024 * 64 // 64MB
+ const skipMaxCap = false // allow to test
if slen <= 0 {
return []byte{}, true
}
- if cap(bs) < slen {
+ if slen <= cap(bs) {
+ return bs[:slen], false
+ }
+ // slen > cap(bs) ... handle memory overload appropriately
+ if skipMaxCap || slen <= maxCap {
return make([]byte, slen), true
}
- return bs[:slen], false
+ return make([]byte, maxCap), true
}
func mapKeyFastKindFor(k reflect.Kind) mapKeyFastKind {