Skip to content

Commit fa2f241

Browse files
author
MarcoFalke
committed
Remove unused GetType() from CBufferedFile and CAutoFile
GetType() is only called in tests, so it is unused and can be removed.
1 parent 5c2b3cd commit fa2f241

File tree

8 files changed

+16
-22
lines changed

8 files changed

+16
-22
lines changed

src/bench/streams_findbyte.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void FindByte(benchmark::Bench& bench)
1616
data[file_size-1] = 1;
1717
fwrite(&data, sizeof(uint8_t), file_size, file);
1818
rewind(file);
19-
CBufferedFile bf(file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0, 0);
19+
CBufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0};
2020

2121
bench.run([&] {
2222
bf.SetPos(0);

src/index/txindex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
7979
return false;
8080
}
8181

82-
CAutoFile file(m_chainstate->m_blockman.OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
82+
CAutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true), CLIENT_VERSION};
8383
if (file.IsNull()) {
8484
return error("%s: OpenBlockFile failed", __func__);
8585
}

src/kernel/mempool_persist.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
4141
if (load_path.empty()) return false;
4242

4343
FILE* filestr{opts.mockable_fopen_function(load_path, "rb")};
44-
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
44+
CAutoFile file{filestr, CLIENT_VERSION};
4545
if (file.IsNull()) {
4646
LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n");
4747
return false;
@@ -157,7 +157,7 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
157157
return false;
158158
}
159159

160-
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
160+
CAutoFile file{filestr, CLIENT_VERSION};
161161

162162
uint64_t version = MEMPOOL_DUMP_VERSION;
163163
file << version;

src/node/blockstorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
822822
bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
823823
{
824824
// Open history file to append
825-
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
825+
CAutoFile fileout{OpenBlockFile(pos), CLIENT_VERSION};
826826
if (fileout.IsNull()) {
827827
return error("WriteBlockToDisk: OpenBlockFile failed");
828828
}
@@ -878,7 +878,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
878878
block.SetNull();
879879

880880
// Open history file to read
881-
CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
881+
CAutoFile filein{OpenBlockFile(pos, true), CLIENT_VERSION};
882882
if (filein.IsNull()) {
883883
return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());
884884
}

src/streams.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,10 @@ class AutoFile
550550
class CAutoFile : public AutoFile
551551
{
552552
private:
553-
const int nType;
554553
const int nVersion;
555554

556555
public:
557-
explicit CAutoFile(std::FILE* file, int type, int version, std::vector<std::byte> data_xor = {}) : AutoFile{file, std::move(data_xor)}, nType{type}, nVersion{version} {}
558-
int GetType() const { return nType; }
556+
explicit CAutoFile(std::FILE* file, int version, std::vector<std::byte> data_xor = {}) : AutoFile{file, std::move(data_xor)}, nVersion{version} {}
559557
int GetVersion() const { return nVersion; }
560558

561559
template<typename T>
@@ -582,7 +580,6 @@ class CAutoFile : public AutoFile
582580
class CBufferedFile
583581
{
584582
private:
585-
const int nType;
586583
const int nVersion;
587584

588585
FILE *src; //!< source file
@@ -632,8 +629,8 @@ class CBufferedFile
632629
}
633630

634631
public:
635-
CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
636-
: nType(nTypeIn), nVersion(nVersionIn), nReadLimit(std::numeric_limits<uint64_t>::max()), nRewind(nRewindIn), vchBuf(nBufSize, std::byte{0})
632+
CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nVersionIn)
633+
: nVersion{nVersionIn}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
637634
{
638635
if (nRewindIn >= nBufSize)
639636
throw std::ios_base::failure("Rewind limit must be less than buffer size");
@@ -650,7 +647,6 @@ class CBufferedFile
650647
CBufferedFile& operator=(const CBufferedFile&) = delete;
651648

652649
int GetVersion() const { return nVersion; }
653-
int GetType() const { return nType; }
654650

655651
void fclose()
656652
{

src/test/fuzz/buffered_file.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ FUZZ_TARGET(buffered_file)
2121
std::optional<CBufferedFile> opt_buffered_file;
2222
FILE* fuzzed_file = fuzzed_file_provider.open();
2323
try {
24-
opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeIntegral<int>());
24+
opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegral<int>());
2525
} catch (const std::ios_base::failure&) {
2626
if (fuzzed_file != nullptr) {
2727
fclose(fuzzed_file);
@@ -62,7 +62,6 @@ FUZZ_TARGET(buffered_file)
6262
});
6363
}
6464
opt_buffered_file->GetPos();
65-
opt_buffered_file->GetType();
6665
opt_buffered_file->GetVersion();
6766
}
6867
}

src/test/streams_tests.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,18 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
260260
// The buffer size (second arg) must be greater than the rewind
261261
// amount (third arg).
262262
try {
263-
CBufferedFile bfbad(file, 25, 25, 222, 333);
263+
CBufferedFile bfbad{file, 25, 25, 333};
264264
BOOST_CHECK(false);
265265
} catch (const std::exception& e) {
266266
BOOST_CHECK(strstr(e.what(),
267267
"Rewind limit must be less than buffer size") != nullptr);
268268
}
269269

270270
// The buffer is 25 bytes, allow rewinding 10 bytes.
271-
CBufferedFile bf(file, 25, 10, 222, 333);
271+
CBufferedFile bf{file, 25, 10, 333};
272272
BOOST_CHECK(!bf.eof());
273273

274-
// These two members have no functional effect.
275-
BOOST_CHECK_EQUAL(bf.GetType(), 222);
274+
// This member has no functional effect.
276275
BOOST_CHECK_EQUAL(bf.GetVersion(), 333);
277276

278277
uint8_t i;
@@ -392,7 +391,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_skip)
392391
rewind(file);
393392

394393
// The buffer is 25 bytes, allow rewinding 10 bytes.
395-
CBufferedFile bf(file, 25, 10, 222, 333);
394+
CBufferedFile bf{file, 25, 10, 333};
396395

397396
uint8_t i;
398397
// This is like bf >> (7-byte-variable), in that it will cause data
@@ -446,7 +445,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
446445

447446
size_t bufSize = InsecureRandRange(300) + 1;
448447
size_t rewindSize = InsecureRandRange(bufSize);
449-
CBufferedFile bf(file, bufSize, rewindSize, 222, 333);
448+
CBufferedFile bf{file, bufSize, rewindSize, 333};
450449
size_t currentPos = 0;
451450
size_t maxPos = 0;
452451
for (int step = 0; step < 100; ++step) {

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4520,7 +4520,7 @@ void ChainstateManager::LoadExternalBlockFile(
45204520
int nLoaded = 0;
45214521
try {
45224522
// This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
4523-
CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE+8, SER_DISK, CLIENT_VERSION);
4523+
CBufferedFile blkdat{fileIn, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8, CLIENT_VERSION};
45244524
// nRewind indicates where to resume scanning in case something goes wrong,
45254525
// such as a block fails to deserialize.
45264526
uint64_t nRewind = blkdat.GetPos();

0 commit comments

Comments
 (0)