refactor: Make HexStr take a span#19660
Conversation
55e2632 to
c0bf0d7
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
src/uint256.cpp
Outdated
There was a problem hiding this comment.
nit: Perhaps use the pre-increment (++i) operator.
src/rpc/request.cpp
Outdated
src/uint256.cpp
Outdated
There was a problem hiding this comment.
Correct me if I'm wrong, but isn't this duplicating memory usage?
There was a problem hiding this comment.
Not really: is is a local variable, all this does is create a small (32 bytes for uint256) temporary buffer on the stack.
(I've opted to do this instead of creating a vector from the iterators, which would be a heap allocation)
|
Concept ACK. |
hebasto
left a comment
There was a problem hiding this comment.
ACK c0bf0d79a8ce532ea1cf0a656acba2db2d8f3112, tested on Linux Mint 20 (x86_64).
src/util/strencodings.h
Outdated
There was a problem hiding this comment.
Does static is really needed here?
src/util/strencodings.cpp
Outdated
There was a problem hiding this comment.
nit:
| static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7', | |
| static constexpr char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7', |
There was a problem hiding this comment.
I'm not sure. Does this make a difference for an array?
Edit: well it works so I don't think there any hurt in changing it…
promag
left a comment
There was a problem hiding this comment.
Code review ACK c0bf0d79a8ce532ea1cf0a656acba2db2d8f3112.
hebasto
left a comment
There was a problem hiding this comment.
re-ACK c0c3262274a0767643b0e283aa5a5dcd30015f9b
|
Concept ACK |
Make HexStr take a span of bytes, instead of an awkward pair of templated iterators.
f0dd45e to
0a8aa62
Compare
|
Squashed the fixme commits |
| obj.pushKV("iswitness", true); | ||
| obj.pushKV("witness_version", (int)id.version); | ||
| obj.pushKV("witness_program", HexStr(id.program, id.program + id.length)); | ||
| obj.pushKV("witness_program", HexStr(Span<const unsigned char>(id.program, id.length))); |
There was a problem hiding this comment.
Maybe we want to give WitnessUnknown .data() and .size() fields to avoid having to do this explicitly. Don't know. Probably not in thie PR though.
|
Nice! |
0a8aa62 refactor: Make HexStr take a span (Wladimir J. van der Laan) Pull request description: Make `HexSt`r take a span of bytes, instead of an awkward pair of templated iterators. This simplifies most of the uses. ACKs for top commit: elichai: Code review ACK 0a8aa62 hebasto: re-ACK 0a8aa62 jonatack: re-ACK 0a8aa62 Tree-SHA512: 6e178ece5cbac62119c857a10299b1e85422938084c3f03063e17119a5129e0c28016e05a6fabaa4c271a7e0a37c7cd89fa47c435ee19b38a5acfe80d00de992
356988e util: make EncodeBase58Check consume Spans (Sebastian Falbesoner) f0fce06 util: make EncodeBase58 consume Spans (Sebastian Falbesoner) Pull request description: This PR improves the interfaces for the functions `EncodeBase58{Check}` by using Spans, in a similar fashion to e.g. PRs #19660, #19687. Note that on the master branch there are currently two versions of `EncodeBase58`: one that takes two pointers (marking begin and end) and another one that takes a `std::vector<unsigned char>` const-ref. The PR branch only leaves one generic Span-interface, both simplifying the interface and allowing more generic containers to be passed. The same is done for `EncodeBase58Check`, where only one interface existed but it's more generic now (e.g. a std::array can be directly passed, as done in the benchmarks). ACKs for top commit: laanwj: Code review ACK 356988e Tree-SHA512: 47cfccdd7f3a2d4694bb8785e6e5fd756daee04ce1652ee59a7822e7e833b4a441ae9362b9bd67ea020d2b5b7d927629c9addb6abaa9881d8564fd3b1257f512
356988e util: make EncodeBase58Check consume Spans (Sebastian Falbesoner) f0fce06 util: make EncodeBase58 consume Spans (Sebastian Falbesoner) Pull request description: This PR improves the interfaces for the functions `EncodeBase58{Check}` by using Spans, in a similar fashion to e.g. PRs bitcoin#19660, bitcoin#19687. Note that on the master branch there are currently two versions of `EncodeBase58`: one that takes two pointers (marking begin and end) and another one that takes a `std::vector<unsigned char>` const-ref. The PR branch only leaves one generic Span-interface, both simplifying the interface and allowing more generic containers to be passed. The same is done for `EncodeBase58Check`, where only one interface existed but it's more generic now (e.g. a std::array can be directly passed, as done in the benchmarks). ACKs for top commit: laanwj: Code review ACK 356988e Tree-SHA512: 47cfccdd7f3a2d4694bb8785e6e5fd756daee04ce1652ee59a7822e7e833b4a441ae9362b9bd67ea020d2b5b7d927629c9addb6abaa9881d8564fd3b1257f512
Summary: ``` Make HexStr take a span of bytes, instead of an awkward pair of templated iterators. ``` Backport of core [[bitcoin/bitcoin#19660 | PR19660]]. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Differential Revision: https://reviews.bitcoinabc.org/D9183
Comment from 6f7b52ac63a71d2706022ca58d69a1a622e0fa37: "The fix for CPubKey is a part of `bitcoin#13557: BIP 174 PSBT Serializations and RPCs` which wasn't backported yet"
Merge bitcoin#19660, bitcoin#19373, bitcoin#19841, bitcoin#13862, bitcoin#13866, bitcoin#17280, bitcoin#17682 and partial bitcoin#19326, bitcoin#14978: Auxiliary Backports
d4408cd Make HexStr() take a Span (furszy) 4c755ec dead code: Remove dead option in HexStr conversion. (Lenny Maiorani) Pull request description: Follow up to #2470. Only the last two commits are from this work. Make `HexStr` take a span of bytes, instead of an awkward pair of templated iterators. Simplifying most of the uses. Adaptation of bitcoin#19660 and bitcoin#15573. ACKs for top commit: random-zebra: utACK d4408cd Tree-SHA512: 541f80e1af9abea2d662e5fc31fc4d5b4057ff93eefeba5632c6ddca391f3b148c8d819a56802720c3932c3c2afb69ddd1efb4890a59ecf1bf5afd6686cd5a67
0a8aa62 refactor: Make HexStr take a span (Wladimir J. van der Laan) Pull request description: Make `HexSt`r take a span of bytes, instead of an awkward pair of templated iterators. This simplifies most of the uses. ACKs for top commit: elichai: Code review ACK 0a8aa62 hebasto: re-ACK 0a8aa62 jonatack: re-ACK 0a8aa62 Tree-SHA512: 6e178ece5cbac62119c857a10299b1e85422938084c3f03063e17119a5129e0c28016e05a6fabaa4c271a7e0a37c7cd89fa47c435ee19b38a5acfe80d00de992
Make
HexStr take a span of bytes, instead of an awkward pair of templated iterators. This simplifies most of the uses.