summaryrefslogtreecommitdiff
path: root/compat/json
diff options
context:
space:
mode:
Diffstat (limited to 'compat/json')
-rw-r--r--compat/json/borrowed_bench_test.go14
-rw-r--r--compat/json/compat_test.go18
-rw-r--r--compat/json/testdata/code.json.gzbin0 -> 120432 bytes
3 files changed, 20 insertions, 12 deletions
diff --git a/compat/json/borrowed_bench_test.go b/compat/json/borrowed_bench_test.go
index e2d74ab..443a13d 100644
--- a/compat/json/borrowed_bench_test.go
+++ b/compat/json/borrowed_bench_test.go
@@ -15,9 +15,13 @@ package json
import (
"bytes"
"compress/gzip"
+ "fmt"
"io"
"os"
+ "reflect"
+ "runtime"
"strings"
+ "sync"
"testing"
)
@@ -325,11 +329,10 @@ func BenchmarkUnmapped(b *testing.B) {
})
}
-/* // MODIFIED: we don't have a cache
func BenchmarkTypeFieldsCache(b *testing.B) {
b.ReportAllocs()
var maxTypes int = 1e6
- if testenv.Builder() != "" {
+ if false { // testenv.Builder() != "" { // MODIFIED: disabled
maxTypes = 1e3 // restrict cache sizes on builders
}
@@ -345,9 +348,9 @@ func BenchmarkTypeFieldsCache(b *testing.B) {
}
// clearClear clears the cache. Other JSON operations, must not be running.
- clearCache := func() {
- fieldCache = sync.Map{}
- }
+ // clearCache := func() { // MODIFIED: use function from compat_test.go
+ // fieldCache = sync.Map{} // MODIFIED: use function from compat_test.go
+ // } // MODIFIED: use function from compat_test.go
// MissTypes tests the performance of repeated cache misses.
// This measures the time to rebuild a cache of size nt.
@@ -389,7 +392,6 @@ func BenchmarkTypeFieldsCache(b *testing.B) {
})
}
}
-*/ // MODIFIED: we don't have a cache
func BenchmarkEncodeMarshaler(b *testing.B) {
b.ReportAllocs()
diff --git a/compat/json/compat_test.go b/compat/json/compat_test.go
index feb850b..203594f 100644
--- a/compat/json/compat_test.go
+++ b/compat/json/compat_test.go
@@ -9,10 +9,16 @@ import (
"io"
"git.lukeshu.com/go/lowmemjson"
- "git.lukeshu.com/go/lowmemjson/internal"
+ "git.lukeshu.com/go/lowmemjson/internal/jsonparse"
+ "git.lukeshu.com/go/lowmemjson/internal/jsonstruct"
+ "git.lukeshu.com/go/lowmemjson/internal/jsontest"
)
-var parseTag = internal.ParseTag
+var (
+ parseTag = jsonstruct.ParseTag
+ clearCache = jsonstruct.ClearCache
+ cachedTypeFields = jsonstruct.IndexStruct
+)
type scanner = lowmemjson.ReEncoderConfig
@@ -21,13 +27,13 @@ func checkValid(in []byte, scan *lowmemjson.ReEncoderConfig) error {
}
func isValidNumber(s string) bool {
- var parser internal.Parser
+ var parser jsonparse.Parser
for _, r := range s {
if t, _ := parser.HandleRune(r); !t.IsNumber() {
return false
}
}
- if t, _ := parser.HandleEOF(); t == internal.RuneTypeError {
+ if t, _ := parser.HandleEOF(); t == jsonparse.RuneTypeError {
return false
}
return true
@@ -51,9 +57,9 @@ type encodeState struct {
}
func (es *encodeState) string(str string, _ bool) {
- internal.EncodeStringFromString(&es.Buffer, str)
+ jsontest.EncodeStringFromString(&es.Buffer, str)
}
func (es *encodeState) stringBytes(str []byte, _ bool) {
- internal.EncodeStringFromBytes(&es.Buffer, str)
+ jsontest.EncodeStringFromBytes(&es.Buffer, str)
}
diff --git a/compat/json/testdata/code.json.gz b/compat/json/testdata/code.json.gz
new file mode 100644
index 0000000..1572a92
--- /dev/null
+++ b/compat/json/testdata/code.json.gz
Binary files differ