neoneo-go/pkg/encoding/bigint
Roman Khimov dfd4f6978f bigint: don't reallocate big.Int in ToBytes(), fix #2864
In some cases n.Add() can reuse the []Word buffer and n.Sub() reallocate it
away. If that happens, we're out of luck with 0.99.0+ versions (since
3945e81857). I'm not sure why it does that, bit
width doesn't change in most of the cases and even if it does, we still have
enough of it in cap() to hold the old Abs() value (when we have a negative
value we in fact decreate its Abs() first and increase it back
afterwards). Still, that's what we have.

So when we have processTokenTransfer() doing Neg/Neg in-place its value is not
affected, but the original []Word bits that are reused by amount value are
(they're shared initially, Amount: *amount).

name                   old time/op    new time/op    delta
ToPreallocatedBytes-8    65.8ns ± 2%    45.6ns ± 2%  -30.73%  (p=0.008 n=5+5)

name                   old alloc/op   new alloc/op   delta
ToPreallocatedBytes-8     0.00B          0.00B          ~     (all equal)

name                   old allocs/op  new allocs/op  delta
ToPreallocatedBytes-8      0.00           0.00          ~     (all equal)
2023-01-10 22:51:45 +03:00
..
bench_test.go bigint: don't reallocate big.Int in ToBytes(), fix #2864 2023-01-10 22:51:45 +03:00
bigint.go bigint: don't reallocate big.Int in ToBytes(), fix #2864 2023-01-10 22:51:45 +03:00
bigint_test.go bigint: don't reallocate big.Int in ToBytes(), fix #2864 2023-01-10 22:51:45 +03:00
doc.go *: add more package-specific documentation 2021-03-19 16:18:45 +03:00
fuzz_test.go encoding: add bigint fuzz test 2022-12-28 11:50:13 +03:00