mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
86dc99f10d
## Issue being fixed or feature implemented Many objects created and functions called by passing `const std::unique_ptr<Obj>& obj` instead directly passing `Obj& obj` In some cases it is indeed needed, but in most cases it is just extra complexity that is better to avoid. Motivation: - providing reference to object instead `unique_ptr` is giving warranty that there's no `nullptr` and no need to keep it in mind - value inside unique_ptr by reference can be changed externally and instead `nullptr` it can turn to real object later (or in opposite) - code is shorter but cleaner Based on that this refactoring is useful as it reduces mental load when reading or writing code. `std::unique` should be used ONLY for owning object, but not for passing it everywhere. ## What was done? Replaced most of usages `std::unique_ptr<Obj>& obj` to `Obj& obj`. Btw, in several cases implementation assumes that object can be nullptr and replacement to reference is not possible. Even using raw pointer is not possible, because the empty std::unique_ptr can be initialized later somewhere in code. For example, in `src/init.cpp` there's called `PeerManager::make` and pass unique_ptr to the `node.llmq_ctx` that would be initialized way later. That is out of scope this PR. List of cases, where reference to `std::unique_ptr` stayed as they are: - `std::unique_ptr<LLMQContext>& llmq_ctx` in `PeerManagerImpl`, `PeerManager` and `CDSNotificationInterface` - `std::unique_ptr<CDeterministicMNManager>& dmnman` in `CDSNotificationInterface` Also `CChainState` have 3 references to `unique_ptr` that can't be replaced too: - `std::unique_ptr<llmq::CChainLocksHandler>& m_clhandler;` - `std::unique_ptr<llmq::CInstantSendManager>& m_isman;` - `std::unique_ptr<llmq::CQuorumBlockProcessor>& m_quorum_block_processor;` ## How Has This Been Tested? Run unit/functional tests. ## Breaking Changes No breaking changes, all of these changes - are internal APIs for Dash Core developers only. ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone --------- Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com> |
||
---|---|---|
.. | ||
test | ||
bdb.cpp | ||
bdb.h | ||
coincontrol.cpp | ||
coincontrol.h | ||
coinselection.cpp | ||
coinselection.h | ||
context.cpp | ||
context.h | ||
crypter.cpp | ||
crypter.h | ||
db.cpp | ||
db.h | ||
fees.cpp | ||
fees.h | ||
init.cpp | ||
interfaces.cpp | ||
ismine.h | ||
load.cpp | ||
load.h | ||
rpcdump.cpp | ||
rpcwallet.cpp | ||
rpcwallet.h | ||
salvage.cpp | ||
salvage.h | ||
scriptpubkeyman.cpp | ||
scriptpubkeyman.h | ||
sqlite.cpp | ||
sqlite.h | ||
wallet.cpp | ||
wallet.h | ||
walletdb.cpp | ||
walletdb.h | ||
wallettool.cpp | ||
wallettool.h | ||
walletutil.cpp | ||
walletutil.h |