get rid of nocopy, do it directly.

This commit is contained in:
fiatjaf
2025-03-10 09:42:55 -03:00
parent bbccd56108
commit f19125af65
4 changed files with 3 additions and 11 deletions

View File

@@ -7,7 +7,6 @@ import (
"unsafe"
"github.com/bytedance/sonic/ast"
"github.com/colduction/nocopy"
)
type sonicVisitorPosition int
@@ -550,7 +549,7 @@ func (smp sonicMessageParser) ParseMessage(message []byte) (Envelope, error) {
sv := &sonicVisitor{smp: &smp}
sv.whereWeAre = inEnvelope
err := ast.Preorder(nocopy.ByteSliceToString(message), sv, nil)
err := ast.Preorder(unsafe.String(unsafe.SliceData(message), len(message)), sv, nil)
return sv.mainEnvelope, err
}

2
go.mod
View File

@@ -11,7 +11,6 @@ require (
github.com/bytedance/sonic v1.13.1
github.com/cloudwego/base64x v0.1.5
github.com/coder/websocket v1.8.12
github.com/colduction/nocopy v0.2.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/dgraph-io/badger/v4 v4.5.0
github.com/dgraph-io/ristretto v1.0.0
@@ -25,7 +24,6 @@ require (
github.com/mailru/easyjson v0.9.0
github.com/mattn/go-sqlite3 v1.14.24
github.com/microcosm-cc/bluemonday v1.0.27
github.com/minio/simdjson-go v0.4.5
github.com/ncruces/go-sqlite3 v0.18.3
github.com/puzpuzpuz/xsync/v3 v3.5.0
github.com/stretchr/testify v1.10.0

4
go.sum
View File

@@ -66,8 +66,6 @@ github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q1
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/colduction/nocopy v0.2.0 h1:9jMLCmIP/wnAWO0FfSXJ4h5HBRe6cBqIqacWw/5sRXY=
github.com/colduction/nocopy v0.2.0/go.mod h1:MO+QBkEnsZYE7QukMAcAq4b0rHpSxOTlVqD3fI34YJs=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -179,8 +177,6 @@ github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBW
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/minio/simdjson-go v0.4.5 h1:r4IQwjRGmWCQ2VeMc7fGiilu1z5du0gJ/I/FsKwgo5A=
github.com/minio/simdjson-go v0.4.5/go.mod h1:eoNz0DcLQRyEDeaPr4Ru6JpjlZPzbA0IodxVJk8lO8E=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

View File

@@ -7,7 +7,6 @@ import (
"sync"
"unsafe"
"github.com/colduction/nocopy"
jsoniter "github.com/json-iterator/go"
"golang.org/x/exp/constraints"
)
@@ -135,7 +134,7 @@ func extractSubID(jsonStr []byte) string {
end := bytes.Index(jsonStr[start:], []byte{'"'})
// get the contents
return nocopy.ByteSliceToString(jsonStr[start : start+end])
return unsafe.String(unsafe.SliceData(jsonStr[start:start+end]), end)
}
func extractEventID(jsonStr []byte) string {
@@ -150,5 +149,5 @@ func extractEventID(jsonStr []byte) string {
start += 4 + offset + 1
// get 64 characters of the id
return nocopy.ByteSliceToString(jsonStr[start : start+64])
return unsafe.String(unsafe.SliceData(jsonStr[start:start+64]), 64)
}