summaryrefslogtreecommitdiff
path: root/vendor/github.com/ugorji/go/codec/helper_not_unsafe.go
diff options
context:
space:
mode:
authorLibravatar Daenney <daenney@users.noreply.github.com>2023-02-25 13:12:40 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-25 12:12:40 +0000
commitecdc8379fa8f9d88faca626e7de748c2afbe4910 (patch)
tree8c20a5826db2136fc89bee45e15355c5899fa65b /vendor/github.com/ugorji/go/codec/helper_not_unsafe.go
parent[bugfix] Fix deleted status causing issues when getting bookmark (#1551) (diff)
downloadgotosocial-ecdc8379fa8f9d88faca626e7de748c2afbe4910.tar.xz
[chore] Update gin to v1.9.0 (#1553)
Diffstat (limited to 'vendor/github.com/ugorji/go/codec/helper_not_unsafe.go')
-rw-r--r--vendor/github.com/ugorji/go/codec/helper_not_unsafe.go62
1 files changed, 49 insertions, 13 deletions
diff --git a/vendor/github.com/ugorji/go/codec/helper_not_unsafe.go b/vendor/github.com/ugorji/go/codec/helper_not_unsafe.go
index 57a3fe26d..10034b86f 100644
--- a/vendor/github.com/ugorji/go/codec/helper_not_unsafe.go
+++ b/vendor/github.com/ugorji/go/codec/helper_not_unsafe.go
@@ -22,6 +22,22 @@ const safeMode = true
const transientSizeMax = 0
const transientValueHasStringSlice = true
+func byteAt(b []byte, index uint) byte {
+ return b[index]
+}
+
+func setByteAt(b []byte, index uint, val byte) {
+ b[index] = val
+}
+
+func byteSliceOf(b []byte, start, end uint) []byte {
+ return b[start:end]
+}
+
+// func byteSliceWithLen(b []byte, length uint) []byte {
+// return b[:length]
+// }
+
func stringView(v []byte) string {
return string(v)
}
@@ -34,8 +50,13 @@ func byteSliceSameData(v1 []byte, v2 []byte) bool {
return cap(v1) != 0 && cap(v2) != 0 && &(v1[:1][0]) == &(v2[:1][0])
}
-func okBytes3(b []byte) (v [4]byte) {
- copy(v[1:], b)
+func okBytes2(b []byte) (v [2]byte) {
+ copy(v[:], b)
+ return
+}
+
+func okBytes3(b []byte) (v [3]byte) {
+ copy(v[:], b)
return
}
@@ -114,8 +135,19 @@ func isEmptyValue(v reflect.Value, tinfos *TypeInfos, recursive bool) bool {
switch v.Kind() {
case reflect.Invalid:
return true
- case reflect.Array, reflect.String:
+ case reflect.String:
return v.Len() == 0
+ case reflect.Array:
+ // zero := reflect.Zero(v.Type().Elem())
+ // can I just check if the whole value is equal to zeros? seems not.
+ // can I just check if the whole value is equal to its zero value? no.
+ // Well, then we check if each value is empty without recursive.
+ for i, vlen := 0, v.Len(); i < vlen; i++ {
+ if !isEmptyValue(v.Index(i), tinfos, false) {
+ return false
+ }
+ }
+ return true
case reflect.Map, reflect.Slice, reflect.Chan:
return v.IsNil() || v.Len() == 0
case reflect.Bool:
@@ -144,16 +176,16 @@ func isEmptyValue(v reflect.Value, tinfos *TypeInfos, recursive bool) bool {
}
// isEmptyStruct is only called from isEmptyValue, and checks if a struct is empty:
-// - does it implement IsZero() bool
-// - is it comparable, and can i compare directly using ==
-// - if checkStruct, then walk through the encodable fields
-// and check if they are empty or not.
+// - does it implement IsZero() bool
+// - is it comparable, and can i compare directly using ==
+// - if checkStruct, then walk through the encodable fields
+// and check if they are empty or not.
func isEmptyStruct(v reflect.Value, tinfos *TypeInfos, recursive bool) bool {
// v is a struct kind - no need to check again.
// We only check isZero on a struct kind, to reduce the amount of times
// that we lookup the rtid and typeInfo for each type as we walk the tree.
- vt := rvType(v)
+ vt := v.Type()
rtid := rt2id(vt)
if tinfos == nil {
tinfos = defTypeInfos
@@ -505,7 +537,7 @@ func rvGetArrayBytes(rv reflect.Value, scratch []byte) (bs []byte) {
}
func rvGetArray4Slice(rv reflect.Value) (v reflect.Value) {
- v = rvZeroAddrK(reflectArrayOf(rvLenSlice(rv), rvType(rv).Elem()), reflect.Array)
+ v = rvZeroAddrK(reflectArrayOf(rvLenSlice(rv), rv.Type().Elem()), reflect.Array)
reflect.Copy(v, rv)
return
}
@@ -615,6 +647,14 @@ func rvLenMap(rv reflect.Value) int {
return rv.Len()
}
+// func copybytes(to, from []byte) int {
+// return copy(to, from)
+// }
+
+// func copybytestr(to []byte, from string) int {
+// return copy(to, from)
+// }
+
// func rvLenArray(rv reflect.Value) int { return rv.Len() }
// ------------ map range and map indexing ----------
@@ -645,10 +685,6 @@ func (e *Encoder) jsondriver() *jsonEncDriver {
// ---------- DECODER optimized ---------------
-func (d *Decoder) checkBreak() bool {
- return d.d.CheckBreak()
-}
-
func (d *Decoder) jsondriver() *jsonDecDriver {
return d.d.(*jsonDecDriver)
}