summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/utf8
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/bytedance/sonic/utf8')
-rw-r--r--vendor/github.com/bytedance/sonic/utf8/utf8.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/vendor/github.com/bytedance/sonic/utf8/utf8.go b/vendor/github.com/bytedance/sonic/utf8/utf8.go
index 52c35fb28..573fe2f5b 100644
--- a/vendor/github.com/bytedance/sonic/utf8/utf8.go
+++ b/vendor/github.com/bytedance/sonic/utf8/utf8.go
@@ -17,6 +17,8 @@
package utf8
import (
+ `runtime`
+
`github.com/bytedance/sonic/internal/rt`
`github.com/bytedance/sonic/internal/native/types`
`github.com/bytedance/sonic/internal/native`
@@ -62,10 +64,18 @@ func CorrectWith(dst []byte, src []byte, repl string) []byte {
// Validate is a simd-accelereated drop-in replacement for the standard library's utf8.Valid.
func Validate(src []byte) bool {
+ if src == nil {
+ return true
+ }
return ValidateString(rt.Mem2Str(src))
}
// ValidateString as Validate, but for string.
func ValidateString(src string) bool {
- return native.ValidateUTF8Fast(&src) == 0
+ if src == "" {
+ return true
+ }
+ ret := native.ValidateUTF8Fast(&src) == 0
+ runtime.KeepAlive(src)
+ return ret
}