stackitem: access value of Array/Struct directly
``` name old time/op new time/op delta ToJSON-8 50.3µs ±34% 47.8µs ± 9% ~ (p=0.971 n=10+10) name old alloc/op new alloc/op delta ToJSON-8 396kB ± 0% 396kB ± 0% -0.10% (p=0.000 n=6+10) name old allocs/op new allocs/op delta ToJSON-8 34.0 ± 0% 18.0 ± 0% -47.06% (p=0.000 n=10+10) ``` Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
dc0a17dd0e
commit
c4eb7db8a5
1 changed files with 7 additions and 1 deletions
|
@ -68,8 +68,14 @@ func toJSON(data []byte, seen map[Item]sliceNoPointer, item Item) ([]byte, error
|
||||||
|
|
||||||
switch it := item.(type) {
|
switch it := item.(type) {
|
||||||
case *Array, *Struct:
|
case *Array, *Struct:
|
||||||
|
var items []Item
|
||||||
|
if a, ok := it.(*Array); ok {
|
||||||
|
items = a.value
|
||||||
|
} else {
|
||||||
|
items = it.(*Struct).value
|
||||||
|
}
|
||||||
|
|
||||||
data = append(data, '[')
|
data = append(data, '[')
|
||||||
items := it.Value().([]Item)
|
|
||||||
for i, v := range items {
|
for i, v := range items {
|
||||||
data, err = toJSON(data, seen, v)
|
data, err = toJSON(data, seen, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue