mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Merge bitcoin/bitcoin#27289: Refactor: Remove unused FlatFilePos::SetNull
fa67b8181c3ecf94395ecc50fd8acd436f1f8c3a Refactor: Remove unused FlatFilePos::SetNull (MarcoFalke) Pull request description: This is unused outside of tests and the default constructor. With C++11, it can be replaced by C++11 member initializers in the default constructor. Beside removing unused code, this also makes it less fragile in light of uninitialized memory. (See also https://github.com/bitcoin/bitcoin/pull/26296#issuecomment-1477801767) If new code needs to set this to null, it can use `std::optional`, or in the worst case re-introduce this method. ACKs for top commit: dergoegge: Code review ACK fa67b8181c3ecf94395ecc50fd8acd436f1f8c3a TheCharlatan: ACK fa67b8181c3ecf94395ecc50fd8acd436f1f8c3a john-moffett: ACK fa67b8181c3ecf94395ecc50fd8acd436f1f8c3a Tree-SHA512: 465c5e3eb4625405c445695d33e09a1fc5185c7dd1e766ba06034fb093880bfc65441d5334f7d9b20e2e417c2075557d86059f59d9648ca0e62a54c699c029b9
This commit is contained in:
parent
dbe2e04d62
commit
0dbafcee46
@ -13,15 +13,15 @@
|
|||||||
|
|
||||||
struct FlatFilePos
|
struct FlatFilePos
|
||||||
{
|
{
|
||||||
int nFile;
|
int nFile{-1};
|
||||||
unsigned int nPos;
|
unsigned int nPos{0};
|
||||||
|
|
||||||
SERIALIZE_METHODS(FlatFilePos, obj)
|
SERIALIZE_METHODS(FlatFilePos, obj)
|
||||||
{
|
{
|
||||||
READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos));
|
READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
FlatFilePos() : nFile(-1), nPos(0) {}
|
FlatFilePos() {}
|
||||||
|
|
||||||
FlatFilePos(int nFileIn, unsigned int nPosIn) :
|
FlatFilePos(int nFileIn, unsigned int nPosIn) :
|
||||||
nFile(nFileIn),
|
nFile(nFileIn),
|
||||||
@ -36,7 +36,6 @@ struct FlatFilePos
|
|||||||
return !(a == b);
|
return !(a == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNull() { nFile = -1; nPos = 0; }
|
|
||||||
bool IsNull() const { return (nFile == -1); }
|
bool IsNull() const { return (nFile == -1); }
|
||||||
|
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
struct CDiskTxPos : public FlatFilePos
|
struct CDiskTxPos : public FlatFilePos
|
||||||
{
|
{
|
||||||
unsigned int nTxOffset; // after header
|
unsigned int nTxOffset{0}; // after header
|
||||||
|
|
||||||
SERIALIZE_METHODS(CDiskTxPos, obj)
|
SERIALIZE_METHODS(CDiskTxPos, obj)
|
||||||
{
|
{
|
||||||
@ -21,15 +21,7 @@ struct CDiskTxPos : public FlatFilePos
|
|||||||
CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
|
CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CDiskTxPos() {
|
CDiskTxPos() {}
|
||||||
SetNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetNull() {
|
|
||||||
FlatFilePos::SetNull();
|
|
||||||
nTxOffset = 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // BITCOIN_INDEX_DISKTXPOS_H
|
#endif // BITCOIN_INDEX_DISKTXPOS_H
|
||||||
|
@ -23,6 +23,9 @@ BOOST_AUTO_TEST_CASE(flatfile_filename)
|
|||||||
|
|
||||||
FlatFileSeq seq2(data_dir / "a", "b", 16 * 1024);
|
FlatFileSeq seq2(data_dir / "a", "b", 16 * 1024);
|
||||||
BOOST_CHECK_EQUAL(seq2.FileName(pos), data_dir / "a" / "b00456.dat");
|
BOOST_CHECK_EQUAL(seq2.FileName(pos), data_dir / "a" / "b00456.dat");
|
||||||
|
|
||||||
|
// Check default constructor IsNull
|
||||||
|
assert(FlatFilePos{}.IsNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(flatfile_open)
|
BOOST_AUTO_TEST_CASE(flatfile_open)
|
||||||
|
@ -25,6 +25,4 @@ FUZZ_TARGET(flatfile)
|
|||||||
assert((*flat_file_pos == *another_flat_file_pos) != (*flat_file_pos != *another_flat_file_pos));
|
assert((*flat_file_pos == *another_flat_file_pos) != (*flat_file_pos != *another_flat_file_pos));
|
||||||
}
|
}
|
||||||
(void)flat_file_pos->ToString();
|
(void)flat_file_pos->ToString();
|
||||||
flat_file_pos->SetNull();
|
|
||||||
assert(flat_file_pos->IsNull());
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user