Skip to content

Commit 12f1fe1

Browse files
authored
allocate slice with struct once and decode into every item (#71)
otherwise every separate struct is allocated on heap, and later is copied into original array.
1 parent 5f4f279 commit 12f1fe1

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

decoder.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,13 @@ func DecodeStructSliceWithLimit[V any, H DecodablePtr[V]](d *Decoder, limit uint
356356
return nil, total, nil
357357
}
358358

359-
value := make([]V, 0, lth)
359+
value := make([]V, lth)
360360
for i := uint32(0); i < lth; i++ {
361-
val, n, err := DecodeStruct[V, H](d)
361+
n, err := H(&value[i]).DecodeScale(d)
362362
total += n
363363
if err != nil {
364364
return nil, total, err
365365
}
366-
value = append(value, val)
367366
}
368367
return value, total, nil
369368
}

0 commit comments

Comments
 (0)