Skip to content

Commit 653a984

Browse files
fjahrMarcoFalke
andcommitted
common: Make arith_uint256 trivially copyable
Replacing the custom code with default behavior 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. Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
1 parent 2562fe1 commit 653a984

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)