Replace char -> uint8_t in serialization where a sign doesn't make sense (char might be signed/unsigned).
refactor: Switch serialize to uint8_t (Bundle 1/2) #21969
pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2105-uin8t changing 8 files +45 −49-
MarcoFalke commented at 5:57 AM on May 17, 2021: member
- fanquake added the label Refactoring on May 17, 2021
-
practicalswift commented at 8:32 AM on May 17, 2021: contributor
Concept ACK
Explicit is better than implicit.
-
in src/addrman.cpp:39 in bbbbad6e20 outdated
33 | @@ -34,7 +34,7 @@ int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std: 34 | 35 | int CAddrInfo::GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const 36 | { 37 | - uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? 'N' : 'K') << nBucket << GetKey()).GetCheapHash(); 38 | + uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << nBucket << GetKey()).GetCheapHash();
hebasto commented at 8:48 AM on May 17, 2021:Does this involve a conversion from the
chartype?
MarcoFalke commented at 11:43 AM on May 17, 2021:Not sure what you mean. This tells the compiler to select the uint8_t-serialization for the ASCII-character
N(orK).None of the ASCII characters use the "sign"-bit, so the serialization of them is identical, regardless of whether they are serialized as
int8_t, char, unsinged char, uint8_t, or signed char
hebasto commented at 12:02 PM on May 17, 2021:I mean that char literals have type
char. And it is not clear for me ifuint8_t{'N'}involves any type conversion?None of the ASCII characters use the "sign"-bit...
Right.
MarcoFalke commented at 7:47 AM on May 20, 2021:Is this a philosophical question?
Previously the compiler produced code to serialize the value
78(which is 'N') by selecting thecharserialization template. Now, the compiler produces code to serialize the value78(which is also 'N') by selecting theuint8_tserialization template.Both templates map to the same code, so the binary should be identical. (Modulo some debug symbols, maybe)
MarcoFalke commented at 8:01 AM on May 20, 2021:On my system this line of the patch doesn't change the binaries for
gccandclangwith-O2.
laanwj commented at 9:40 AM on May 27, 2021:It would have been nice to have constants for these instead of hardcoding them, for documentation purposes, but the change looks fine to me.
kristapsk commented at 10:32 AM on May 17, 2021: contributorConcept ACK
DrahtBot commented at 2:53 AM on May 19, 2021: member<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
No conflicts as of last run.
theStack commented at 3:07 PM on May 24, 2021: memberConcept ACK
DrahtBot added the label Needs rebase on May 26, 2021laanwj commented at 9:40 AM on May 27, 2021: memberCode review ACK bbbbad6e20cece7fa2884737c223e10b2b0d7066
refactor: Switch serialize to uint8_t (1/n) ffff0d0442MarcoFalke force-pushed on May 31, 2021DrahtBot removed the label Needs rebase on May 31, 2021practicalswift commented at 1:11 PM on May 31, 2021: contributorcr ACK ffff0d04425a616c14fc4a562e8ef93d286705f8: patch looks correct and commit hash is ffffresh (was bbbbadass)
kristapsk approvedkristapsk commented at 3:08 PM on May 31, 2021: contributorACK ffff0d04425a616c14fc4a562e8ef93d286705f8
MarcoFalke merged this on Jun 1, 2021MarcoFalke closed this on Jun 1, 2021MarcoFalke deleted the branch on Jun 1, 2021sidhujag referenced this in commit 579436d522 on Jun 1, 2021gwillen referenced this in commit f39648bfe5 on Jun 1, 2022DrahtBot locked this on Aug 16, 2022
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 15:14 UTC
More mirrored repositories can be found on mirror.b10c.me