Skip to content

Commit f757da8

Browse files
committed
Merge bitcoin/bitcoin#33332: common: Make arith_uint256 trivially copyable
653a984 common: Make arith_uint256 trivially copyable (Fabian Jahr) Pull request description: Makes `arith_uint256`/`base_uint` trivially copyable by removing the custom copy constructor and copy assignment operators. Removing of the custom code should not result in a change of behavior since `base_uint` contains a simple array of `uint32_t` and compiler generated versions of the code could be better optimized. This was suggested by maflcko here: bitcoin/bitcoin#30469 (review) ACKs for top commit: Raimo33: ACK 653a984 l0rinc: ACK 653a984 achow101: ACK 653a984 hodlinator: re-ACK 653a984 Tree-SHA512: 38db5220a2cf773c0c5fb5591671e329b6b87458d972db4f5f3f98c025ec329a8c39b32b5bc24ef8b50b1002b43bb248d8b35aa1c9a56c68c6bbd1d470485bd7
2 parents e416dc2 + 653a984 commit f757da8

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/arith_uint256.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,8 @@ class base_uint
3737
pn[i] = 0;
3838
}
3939

40-
base_uint(const base_uint& b)
41-
{
42-
for (int i = 0; i < WIDTH; i++)
43-
pn[i] = b.pn[i];
44-
}
45-
46-
base_uint& operator=(const base_uint& b)
47-
{
48-
if (this != &b) {
49-
for (int i = 0; i < WIDTH; i++)
50-
pn[i] = b.pn[i];
51-
}
52-
return *this;
53-
}
40+
base_uint(const base_uint& b) = default;
41+
base_uint& operator=(const base_uint& b) = default;
5442

5543
base_uint(uint64_t b)
5644
{
@@ -272,6 +260,9 @@ class arith_uint256 : public base_uint<256> {
272260
friend arith_uint256 UintToArith256(const uint256 &);
273261
};
274262

263+
// Keeping the trivially copyable property is beneficial for performance
264+
static_assert(std::is_trivially_copyable_v<arith_uint256>);
265+
275266
uint256 ArithToUint256(const arith_uint256 &);
276267
arith_uint256 UintToArith256(const uint256 &);
277268

0 commit comments

Comments
 (0)