fix typo & add test for noCopy

This commit is contained in:
Alexandr Mayorskiy
2020-04-12 21:35:45 +03:00
parent 5c9438b0d1
commit 6c2d82a4da
2 changed files with 13 additions and 2 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ Besides standart json tag options like 'omitempty' the following are supported:
objects which are not hold in memory after decoding and immediate usage.
Note if string requires unescaping it will be processed as normally.
* 'intern' - string "interning" (deduplication) to save memory when the very
same string dictionory values are often met all over the structure.
same string dictionary values are often met all over the structure.
See below for more details.
## Generated Marshaler/Unmarshaler Funcs
+12 -1
View File
@@ -48,6 +48,17 @@ func TestNocopy(t *testing.T) {
}
})
if allocsPerRun != 1 {
t.Fatalf("expected 1 allocs, got %f", allocsPerRun)
t.Fatalf("noCopy field unmarshal: expected 1 allocs, got %f", allocsPerRun)
}
data = []byte(`{"a": "valueNoCopy"}`)
allocsPerRun = testing.AllocsPerRun(1000, func() {
easyjson.Unmarshal(data, &res)
if res.A != "valueNoCopy" {
t.Fatalf("wrong value: %q", res.A)
}
})
if allocsPerRun != 2 {
t.Fatalf("copy field unmarshal: expected 2 allocs, got %f", allocsPerRun)
}
}