Remove redundant copy constructors #17349
pull MarcoFalke wants to merge 2 commits into bitcoin:master from MarcoFalke:1911-copyConstructorWhy changing 2 files +1 −8-
MarcoFalke commented at 10:20 pm on November 1, 2019: memberI fail to see why people add these copy constructors manually without explanation, when the compiler can generate them at least as good automatically with less code.
-
refactor: Remove redundant PSBT copy constructor
The default (i.e., generated by a compiler) copy constructor does the same things. Also this prevents -Wdeprecated-copy warning for implicitly declared operator= in GCC 9.
-
bench: Remove redundant copy constructor in mempool_stress fa8919889f
-
MarcoFalke added the label Refactoring on Nov 1, 2019
-
MarcoFalke commented at 10:21 pm on November 1, 2019: membercc @achow101 @JeremyRubin. Is there any reason for this that I am missing?
-
theuni commented at 10:26 pm on November 1, 2019: memberThis likely has the side-effect of enabling moves, as they would’ve been implicitly disabled by the explicit assignment operator/copy ctor. Is that desirable?
-
MarcoFalke commented at 10:39 pm on November 1, 2019: memberIf a move is not desired, why couldn’t this be achieved with
delete
anddefault
keywords and proper documentation instead? https://en.cppreference.com/w/cpp/language/move_constructor -
in src/bench/mempool_stress.cpp:26 in fa8919889f
22@@ -23,12 +23,6 @@ struct Available { 23 size_t vin_left{0}; 24 size_t tx_count; 25 Available(CTransactionRef& ref, size_t tx_count) : ref(ref), tx_count(tx_count){} 26- Available& operator=(Available other) {
promag commented at 10:52 pm on November 1, 2019:fa8919889f3c1bd3e2700ecbb56493e3cd1e25ad
Is this a copy operator? 🤔
promag commented at 10:52 pm on November 1, 2019: memberACK fa8919889f3c1bd3e2700ecbb56493e3cd1e25ad.JeremyRubin commented at 11:43 pm on November 1, 2019: contributorI can’t recall exactly but I think it goes something like this:
Write code without any stupid generatable stuff.
Get compiler error.
Add stupid generatable thing manually.
Continue coding.
Get new compiler error later.
Add thing 2 for that error.
Thing 2 now makes thing 1 redundant.
Compiler doesn’t warn that thing 1 is now redundant.
git commit
DrahtBot commented at 1:26 am on November 2, 2019: memberThe following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #17268 (Epoch Mempool by JeremyRubin)
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.
laanwj commented at 8:50 am on November 2, 2019: memberI also had done this in #16995. There’s this warning that makes people add copy constructors:
0implicitly-declared ‘PartiallySignedTransaction& PartiallySignedTransaction::operator=(const PartiallySignedTransaction&)’ is deprecated [-Wdeprecated-copy]
(in this case the better solution was to remove the custom constructor, but the straightforward “fix” for this warning is to add an explicit copy implementation)
(yes, what @JeremyRubin says, it’s like warning/error pinball sometimes)
jonatack commented at 10:50 am on November 2, 2019: memberACK fa8919889f3c1bd3e2700ecbb56493e3cd1e25ad
This appears correct, also afaict per https://en.cppreference.com/w/cpp/language/copy_constructor and https://en.cppreference.com/w/cpp/language/move_constructor. No related build warnings with bench and debug enabled. Regenerated bench data, ran bench_bitcoin and bitcoind.
0(pr/17349) $ src/bench/bench_bitcoin 1WARNING: This is a debug build - may result in slower benchmarks. 2# Benchmark, evals, iterations, total, min, max, median 3AssembleBlock, 5, 700, 27.9197, 0.00720689, 0.00938161, 0.00797799 4Base58CheckEncode, 5, 320000, 117.597, 7.07593e-05, 7.93047e-05, 7.24769e-05 5... 6ComplexMemPool, 5, 1, 16.6861, 3.19937, 3.4615, 3.38646 7... 8MempoolEviction, 5, 41000, 88.9042, 0.000383962, 0.000517717, 0.000428901 9... 10RpcMempool, 5, 40, 12.4578, 0.0601209, 0.0654556, 0.0620714
MarcoFalke referenced this in commit fba574c908 on Nov 4, 2019MarcoFalke merged this on Nov 4, 2019MarcoFalke closed this on Nov 4, 2019
MarcoFalke deleted the branch on Nov 4, 2019MarkLTZ referenced this in commit 97dfbbb0a0 on Nov 17, 2019jasonbcox referenced this in commit ac76cc89e1 on Sep 11, 2020MarcoFalke locked this on Dec 16, 2021
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: 2024-11-17 18:12 UTC
More mirrored repositories can be found on mirror.b10c.me