fix: bug with shared pointer in new jit mode

This commit is contained in:
Vikram Rangnekar
2020-06-03 18:19:07 -04:00
parent 0ce129de14
commit 82cc712a93
14 changed files with 75 additions and 56 deletions

13
jsn/bench.1 Normal file
View File

@ -0,0 +1,13 @@
goos: darwin
goarch: amd64
pkg: github.com/dosco/super-graph/jsn
BenchmarkGet
BenchmarkGet-16 13898 85293 ns/op 3328 B/op 2 allocs/op
BenchmarkFilter
BenchmarkFilter-16 189328 6341 ns/op 448 B/op 1 allocs/op
BenchmarkStrip
BenchmarkStrip-16 219765 5543 ns/op 224 B/op 1 allocs/op
BenchmarkReplace
BenchmarkReplace-16 100899 12022 ns/op 416 B/op 1 allocs/op
PASS
ok github.com/dosco/super-graph/jsn 6.029s

View File

@ -2,17 +2,19 @@ package jsn
import (
"bytes"
"github.com/cespare/xxhash/v2"
"hash/maphash"
)
// Filter function filters the JSON keeping only the provided keys and removing all others
func Filter(w *bytes.Buffer, b []byte, keys []string) error {
var err error
kmap := make(map[uint64]struct{}, len(keys))
h := maphash.Hash{}
for i := range keys {
kmap[xxhash.Sum64String(keys[i])] = struct{}{}
h.WriteString(keys[i])
kmap[h.Sum64()] = struct{}{}
h.Reset()
}
// is an list
@ -132,7 +134,11 @@ func Filter(w *bytes.Buffer, b []byte, keys []string) error {
cb := b[s:(e + 1)]
e = 0
if _, ok := kmap[xxhash.Sum64(k)]; !ok {
h.Write(k)
_, ok := kmap[h.Sum64()]
h.Reset()
if !ok {
continue
}

View File

@ -1,7 +1,7 @@
package jsn
import (
"github.com/cespare/xxhash/v2"
"hash/maphash"
)
const (
@ -41,9 +41,12 @@ func Value(b []byte) []byte {
// Keys function fetches values for the provided keys
func Get(b []byte, keys [][]byte) []Field {
kmap := make(map[uint64]struct{}, len(keys))
h := maphash.Hash{}
for i := range keys {
kmap[xxhash.Sum64(keys[i])] = struct{}{}
h.Write(keys[i])
kmap[h.Sum64()] = struct{}{}
h.Reset()
}
res := make([]Field, 0, 20)
@ -141,7 +144,9 @@ func Get(b []byte, keys [][]byte) []Field {
}
if e != 0 {
_, ok := kmap[xxhash.Sum64(k)]
h.Write(k)
_, ok := kmap[h.Sum64()]
h.Reset()
if ok {
res = append(res, Field{k, b[s:(e + 1)]})

View File

@ -3,8 +3,7 @@ package jsn
import (
"bytes"
"errors"
"github.com/cespare/xxhash/v2"
"hash/maphash"
)
// Replace function replaces key-value pairs provided in the `from` argument with those in the `to` argument
@ -18,7 +17,7 @@ func Replace(w *bytes.Buffer, b []byte, from, to []Field) error {
return err
}
h := xxhash.New()
h := maphash.Hash{}
tmap := make(map[uint64]int, len(from))
for i, f := range from {