Commit graph

110 commits

Author SHA1 Message Date
Roman Khimov
d40ccb3e57 util: add Compare to Uint160
It's useful for slices-based sorting/finding.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
9cce148d83 *: use maps.Equal/slices.Equal where appropriate
Testing for equality has never been easier.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
9e112fc024 *: use slices.Clone instead of make/copy
It's much easier this way.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
c7b623cc38 *: drop pkg/util/slice, use slices.Reverse
This also removes bigint.FromBytesUnsigned(), it's not used very often and
it's somewhat misleading in the bigint package (which is supposed to use a
very specific enconding).

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
963e22ea95 *: replace slice.Clean() with clear()
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Leonard Lyubich
c975d728e8 *: Convert slices to arrays instead of copy where possible
Became possible with Go 1.20.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
2024-07-05 20:36:22 +04:00
Anna Shaleva
8162e9033d *: replace slice.Copy with bytes.Clone
And refactor some code a bit, don't use bytes.Clone where type-specific
helpers may be used instead.

Close #2907.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-03-05 13:54:10 +03:00
Anna Shaleva
6b21ad9922 *: replace interface{} with any keyword
Everywhere including examples, external interop APIs, bindings generators
code and in other valuable places. A couple of `interface{}` usages are
intentionally left in the CHANGELOG.md, documentation and tests.
2023-04-04 13:22:42 +03:00
Roman Khimov
74bf4a8e3f slice: add Clean microfunction
To be used for various cleaning purposes, one line is better than three lines.
2022-09-02 14:44:32 +03:00
Anna Shaleva
916f2293b8 *: apply go 1.19 formatter heuristics
And make manual corrections where needed. See the "Common mistakes
and pitfalls" section of https://tip.golang.org/doc/comment.
2022-08-09 15:37:52 +03:00
Roman Khimov
edb6ca8926
Merge pull request #2531 from nspcc-dev/perf
Minor performance improvements
2022-06-03 10:40:56 +03:00
Roman Khimov
b0744c2b21 util: optimize MarshalJSON allocations
name                  old time/op    new time/op    delta
Uint256MarshalJSON-8     230ns ± 6%      83ns ±13%  -63.78%  (p=0.000 n=8+10)

name                  old alloc/op   new alloc/op   delta
Uint256MarshalJSON-8      320B ± 0%       80B ± 0%  -75.00%  (p=0.000 n=10+10)

name                  old allocs/op  new allocs/op  delta
Uint256MarshalJSON-8      5.00 ± 0%      1.00 ± 0%  -80.00%  (p=0.000 n=10+10)
2022-06-02 15:38:39 +03:00
Evgeniy Stratonikov
ec21c14ca9 gomod: upgrade yaml package from v2 to v3
Close #2085.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-05-30 15:26:17 +03:00
Elizaveta Chichindaeva
28908aa3cf [#2442] English Check
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
2022-05-04 19:48:27 +03:00
Evgeniy Stratonikov
c212b2be95 util: allow to marshal Uint160 in YAML
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-02-21 10:38:20 +03:00
Evgeniy Stratonikov
8c31831626 util: reduce allocations in util.Uint256DecodeStringLE
It is used a lot in clients (including our benchmark).
`Uint160` is already optimized.

```
name                     old time/op    new time/op    delta
Uint256DecodeStringLE-8     150ns ±15%     112ns ± 3%  -25.23%  (p=0.000 n=10+10)

name                     old alloc/op   new alloc/op   delta
Uint256DecodeStringLE-8     96.0B ± 0%     64.0B ± 0%  -33.33%  (p=0.000 n=10+10)

name                     old allocs/op  new allocs/op  delta
Uint256DecodeStringLE-8      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-17 16:53:39 +03:00
Roman Khimov
19717dd9a8 slice: introduce common Copy helper
It's a bit more convenient to use.
2021-07-19 22:57:55 +03:00
Roman Khimov
a54e3516d1 slice: add Reverse function, deduplicate code a bit 2021-07-19 22:57:55 +03:00
Roman Khimov
100e97d772 util: move ArrayReverse into package of its own
Leave just uint160 and uint256 types in util.
2021-07-19 22:57:55 +03:00
Roman Khimov
aab18c3083 stackitem: introduce Convertible interface
We have a lot of native contract types that are converted to stack items
before serialization, then deserialized as stack items and converted back to
regular structures. stackitem.Convertible allows to remove a lot of repetitive
io.Serializable code.

This also introduces to/from converter in testserdes which unfortunately
required to change util tests to avoid circular references.
2021-07-19 15:42:42 +03:00
Roman Khimov
9d2712573f *: enable godot linter and fix all its warnings
It's important for NeoGo to have clean documentation. No functional changes.
2021-05-12 23:17:03 +03:00
Roman Khimov
cfc067dd24 *: remove dead code
Found by deadcode via golangci-lint.
2021-05-12 18:13:14 +03:00
Roman Khimov
158f0d9d9c native/vm: add script check for deployed contracts
Refs. #1699.
2021-02-09 22:31:26 +03:00
Roman Khimov
a6e25cffde bitfield: add basic bit field package
Strange as it is but I wasn't able to find any good bit field
implementation. Most of them are limited to 64 bits, some allow for wider
values (like https://github.com/emef/bitfield) but even they're not that
efficient (using bytes instead of wider types). This this minimalistic thing.
2021-02-09 22:31:26 +03:00
Evgenii Stratonikov
e4c3339c91 util: move Fixed8 to encoding/fixedn package 2020-12-09 11:18:18 +03:00
Evgenii Stratonikov
7d91a3a89e pkg: move internal/ package to the root directory
This way we can use it in scripts and cli.
2020-11-24 16:39:56 +03:00
Roman Khimov
292c186665 *: use proper YAML library import path, fix #1306 2020-08-12 16:31:06 +03:00
Anna Shaleva
c3e08afe34 util: fixed typo in method description 2020-05-20 23:26:51 +03:00
Anna Shaleva
d1ec01c45e util: implement Serializable interface over Uint160 2020-05-04 11:49:14 +03:00
Evgenii Stratonikov
9abda40171 testserdes: implement helpers for encode/decode routines
Frequently one needs to check if struct serializes/deserializes
properly. This commit implements helpers for such cases including:
1. JSON
2. io.Serializable interface
2020-03-27 10:27:46 +03:00
Anna Shaleva
2001a40312 util: JSONify uint160 using LE instead of BE
closes #769
2020-03-23 17:38:58 +03:00
Evgenii Stratonikov
d447064515 util: implement FixedN from string
When working with NEP5 contracts we frequently need
to parse fixed-point decimals with arbitrary precision.
2020-03-10 13:02:14 +03:00
Roman Khimov
823798514a util: rename Int64Value to IntegralValue, add FractionalValue
Makes it's interface more clear and allows to easily access fractional part.
2020-03-04 19:23:23 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +03:00
Evgenii Stratonikov
24bb66e606 util: fix a bug with not copying slice of len=1 in ArrayReverse
ArrayReverse copies it's argument only if it's len is > 1.
It needs to be consistent in all cases.
2020-02-06 12:15:35 +03:00
Evgenii Stratonikov
d07d6f3371 util: refactor tests for ArrayReverse 2020-02-06 12:15:35 +03:00
Evgenii Stratonikov
2f865480d3 util: add YAML marshaler to Fixed8 2020-01-22 14:31:57 +03:00
Roman Khimov
54d888ba70 io: add type-specific read/write methods
This seriously improves the serialization/deserialization performance for
several reasons:
 * no time spent in `binary` reflection
 * no memory allocations being made on every read/write
 * uses fast ReadBytes everywhere it's appropriate

It also makes Fixed8 Serializable just for convenience.
2019-12-12 20:19:50 +03:00
Roman Khimov
5b6c5af704 *: implement EncodeBinary with pointer receivers where appropriate
Everywhere except ParamType (which is just a byte), reduce copying things
around for no real reason.
2019-12-09 18:25:15 +03:00
Evgenii Stratonikov
fccb008594 io: implement ReadBytes() 2019-12-09 15:00:15 +03:00
Roman Khimov
e4d821f32d
Merge pull request #546 from nspcc-dev/write-optimizations
Write optimizations
2019-12-06 19:40:38 +03:00
Roman Khimov
844491d365 *: use more efficient WriteBytes where appropriate
Before this patch on block import we could easily be spending more than 6
seconds out of 30 in Uint256 encoding for UnspentBalance, now it's completely
off the radar.
2019-12-06 18:22:21 +03:00
Evgenii Stratonikov
aa20a95181 util: add Uint256DecodeStringBE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
72fe884faa util: add Uint160DecodeStringLE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
07e832f046 util: add Uint160DecodeBytesLE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
09b295d727 util: add Uint160.Reverse() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
9e04e61533 util: make Uint160Size public 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
7179e4ba9f util: add LE suffix to Uint256 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
57efad912c util: add LE suffix to Uint160 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
ab922c1810 util: add missing tests for Uint256 2019-11-25 11:55:26 +03:00