summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/ast/decode.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-06-01 22:20:16 +0100
committerLibravatar GitHub <noreply@github.com>2023-06-01 22:20:16 +0100
commit55aacaf4b07c1921061245cbaa3d307e97cf3c29 (patch)
treed969c5d9728566de1e794e19c5b19d3b660f790e /vendor/github.com/bytedance/sonic/ast/decode.go
parent[chore/frontend] refactor header templating, add apple-touch-icon (#1850) (diff)
downloadgotosocial-55aacaf4b07c1921061245cbaa3d307e97cf3c29.tar.xz
[chore]: Bump github.com/gin-gonic/gin from 1.9.0 to 1.9.1 (#1855)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/bytedance/sonic/ast/decode.go')
-rw-r--r--vendor/github.com/bytedance/sonic/ast/decode.go161
1 files changed, 153 insertions, 8 deletions
diff --git a/vendor/github.com/bytedance/sonic/ast/decode.go b/vendor/github.com/bytedance/sonic/ast/decode.go
index d54e98318..6a5f6fea3 100644
--- a/vendor/github.com/bytedance/sonic/ast/decode.go
+++ b/vendor/github.com/bytedance/sonic/ast/decode.go
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2022 ByteDance Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package ast
import (
@@ -24,6 +40,7 @@ func isSpace(c byte) bool {
return (int(1<<c) & _blankCharsMask) != 0
}
+//go:nocheckptr
func skipBlank(src string, pos int) int {
se := uintptr(rt.IndexChar(src, len(src)))
sp := uintptr(rt.IndexChar(src, pos))
@@ -77,6 +94,7 @@ func decodeFalse(src string, pos int) (ret int) {
return -int(types.ERR_INVALID_CHAR)
}
+//go:nocheckptr
func decodeString(src string, pos int) (ret int, v string) {
ret, ep := skipString(src, pos)
if ep == -1 {
@@ -112,6 +130,7 @@ func isDigit(c byte) bool {
return c >= '0' && c <= '9'
}
+//go:nocheckptr
func decodeInt64(src string, pos int) (ret int, v int64, err error) {
sp := uintptr(rt.IndexChar(src, pos))
ss := uintptr(sp)
@@ -161,6 +180,7 @@ func isNumberChars(c byte) bool {
return (c >= '0' && c <= '9') || c == '+' || c == '-' || c == 'e' || c == 'E' || c == '.'
}
+//go:nocheckptr
func decodeFloat64(src string, pos int) (ret int, v float64, err error) {
sp := uintptr(rt.IndexChar(src, pos))
ss := uintptr(sp)
@@ -255,6 +275,7 @@ func decodeValue(src string, pos int) (ret int, v types.JsonState) {
}
}
+//go:nocheckptr
func skipNumber(src string, pos int) (ret int) {
sp := uintptr(rt.IndexChar(src, pos))
se := uintptr(rt.IndexChar(src, len(src)))
@@ -281,7 +302,7 @@ func skipNumber(src string, pos int) (ret int) {
} else if nextNeedDigit {
return -int(types.ERR_INVALID_CHAR)
} else if c == '.' {
- if !lastIsDigit || pointer || sp == ss {
+ if !lastIsDigit || pointer || exponent || sp == ss {
return -int(types.ERR_INVALID_CHAR)
}
pointer = true
@@ -319,6 +340,7 @@ func skipNumber(src string, pos int) (ret int) {
return int(uintptr(sp) - uintptr((*rt.GoString)(unsafe.Pointer(&src)).Ptr))
}
+//go:nocheckptr
func skipString(src string, pos int) (ret int, ep int) {
if pos+1 >= len(src) {
return -int(types.ERR_EOF), -1
@@ -327,6 +349,7 @@ func skipString(src string, pos int) (ret int, ep int) {
sp := uintptr(rt.IndexChar(src, pos))
se := uintptr(rt.IndexChar(src, len(src)))
+ // not start with quote
if *(*byte)(unsafe.Pointer(sp)) != '"' {
return -int(types.ERR_INVALID_CHAR), -1
}
@@ -344,18 +367,16 @@ func skipString(src string, pos int) (ret int, ep int) {
}
sp += 1
if c == '"' {
- break
+ return int(uintptr(sp) - uintptr((*rt.GoString)(unsafe.Pointer(&src)).Ptr)), ep
}
}
- if sp > se {
- return -int(types.ERR_EOF), -1
- }
-
runtime.KeepAlive(src)
- return int(uintptr(sp) - uintptr((*rt.GoString)(unsafe.Pointer(&src)).Ptr)), ep
+ // not found the closed quote until EOF
+ return -int(types.ERR_EOF), -1
}
+//go:nocheckptr
func skipPair(src string, pos int, lchar byte, rchar byte) (ret int) {
if pos+1 >= len(src) {
return -int(types.ERR_EOF)
@@ -403,7 +424,7 @@ func skipPair(src string, pos int, lchar byte, rchar byte) (ret int) {
return int(uintptr(sp) - uintptr((*rt.GoString)(unsafe.Pointer(&src)).Ptr))
}
-func skipValue(src string, pos int) (ret int, start int) {
+func skipValueFast(src string, pos int) (ret int, start int) {
pos = skipBlank(src, pos)
if pos < 0 {
return pos, -1
@@ -428,3 +449,127 @@ func skipValue(src string, pos int) (ret int, start int) {
}
return ret, pos
}
+
+func skipValue(src string, pos int) (ret int, start int) {
+ pos = skipBlank(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+ switch c := src[pos]; c {
+ case 'n':
+ ret = decodeNull(src, pos)
+ case '"':
+ ret, _ = skipString(src, pos)
+ case '{':
+ ret, _ = skipObject(src, pos)
+ case '[':
+ ret, _ = skipArray(src, pos)
+ case 't':
+ ret = decodeTrue(src, pos)
+ case 'f':
+ ret = decodeFalse(src, pos)
+ case '-', '+', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
+ ret = skipNumber(src, pos)
+ default:
+ ret = -int(types.ERR_INVALID_CHAR)
+ }
+ return ret, pos
+}
+
+func skipObject(src string, pos int) (ret int, start int) {
+ start = skipBlank(src, pos)
+ if start < 0 {
+ return start, -1
+ }
+
+ if src[start] != '{' {
+ return -int(types.ERR_INVALID_CHAR), -1
+ }
+
+ pos = start + 1
+ pos = skipBlank(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+ if src[pos] == '}' {
+ return pos + 1, start
+ }
+
+ for {
+ pos, _ = skipString(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+
+ pos = skipBlank(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+ if src[pos] != ':' {
+ return -int(types.ERR_INVALID_CHAR), -1
+ }
+
+ pos++
+ pos, _ = skipValue(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+
+ pos = skipBlank(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+ if src[pos] == '}' {
+ return pos + 1, start
+ }
+ if src[pos] != ',' {
+ return -int(types.ERR_INVALID_CHAR), -1
+ }
+
+ pos++
+ pos = skipBlank(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+
+ }
+}
+
+func skipArray(src string, pos int) (ret int, start int) {
+ start = skipBlank(src, pos)
+ if start < 0 {
+ return start, -1
+ }
+
+ if src[start] != '[' {
+ return -int(types.ERR_INVALID_CHAR), -1
+ }
+
+ pos = start + 1
+ pos = skipBlank(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+ if src[pos] == ']' {
+ return pos + 1, start
+ }
+
+ for {
+ pos, _ = skipValue(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+
+ pos = skipBlank(src, pos)
+ if pos < 0 {
+ return pos, -1
+ }
+ if src[pos] == ']' {
+ return pos + 1, start
+ }
+ if src[pos] != ',' {
+ return -int(types.ERR_INVALID_CHAR), -1
+ }
+ pos++
+ }
+}