From fa389d902fbf5fac19fba8c5d0c5e0a25f15ca63 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 4 Jul 2023 18:59:49 +0200 Subject: refactor: Drop unused fclose() from BufferedFile This was only explicitly used in the tests, where it can be replaced by wrapping the original raw file pointer into a CAutoFile on creation and then calling CAutoFile::fclose(). Also, it was used in LoadExternalBlockFile(), where it can also be replaced by the (implicit call to the) CAutoFile destructor after wrapping the original raw file pointer in a CAutoFile. --- src/bench/load_external.cpp | 5 +++-- src/bench/streams_findbyte.cpp | 16 ++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src/bench') diff --git a/src/bench/load_external.cpp b/src/bench/load_external.cpp index 252cbb163b..7cfade9c79 100644 --- a/src/bench/load_external.cpp +++ b/src/bench/load_external.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -54,8 +55,8 @@ static void LoadExternalBlockFile(benchmark::Bench& bench) bench.run([&] { // "rb" is "binary, O_RDONLY", positioned to the start of the file. // The file will be closed by LoadExternalBlockFile(). - FILE* file{fsbridge::fopen(blkfile, "rb")}; - testing_setup->m_node.chainman->LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent); + CAutoFile file{fsbridge::fopen(blkfile, "rb"), CLIENT_VERSION}; + testing_setup->m_node.chainman->LoadExternalBlockFile(file.Get(), &pos, &blocks_with_unknown_parent); }); fs::remove(blkfile); } diff --git a/src/bench/streams_findbyte.cpp b/src/bench/streams_findbyte.cpp index 22b8f1b356..b97f130c67 100644 --- a/src/bench/streams_findbyte.cpp +++ b/src/bench/streams_findbyte.cpp @@ -4,19 +4,23 @@ #include -#include #include +#include + +#include +#include +#include static void FindByte(benchmark::Bench& bench) { // Setup - FILE* file = fsbridge::fopen("streams_tmp", "w+b"); + CAutoFile file{fsbridge::fopen("streams_tmp", "w+b"), 0}; const size_t file_size = 200; uint8_t data[file_size] = {0}; data[file_size-1] = 1; - fwrite(&data, sizeof(uint8_t), file_size, file); - rewind(file); - BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0}; + file << data; + std::rewind(file.Get()); + BufferedFile bf{file.Get(), /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0}; bench.run([&] { bf.SetPos(0); @@ -24,7 +28,7 @@ static void FindByte(benchmark::Bench& bench) }); // Cleanup - bf.fclose(); + file.fclose(); fs::remove("streams_tmp"); } -- cgit v1.2.3 From 9999b89cd37fb2a23c5ebcd91d9cb31d69375933 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 4 Jul 2023 17:09:13 +0200 Subject: Make BufferedFile to be a CAutoFile wrapper This refactor allows to forward some calls to the underlying CAutoFile, instead of re-implementing the logic in the buffered file. --- src/bench/load_external.cpp | 2 +- src/bench/streams_findbyte.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bench') diff --git a/src/bench/load_external.cpp b/src/bench/load_external.cpp index 7cfade9c79..3b100d97b0 100644 --- a/src/bench/load_external.cpp +++ b/src/bench/load_external.cpp @@ -56,7 +56,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench) // "rb" is "binary, O_RDONLY", positioned to the start of the file. // The file will be closed by LoadExternalBlockFile(). CAutoFile file{fsbridge::fopen(blkfile, "rb"), CLIENT_VERSION}; - testing_setup->m_node.chainman->LoadExternalBlockFile(file.Get(), &pos, &blocks_with_unknown_parent); + testing_setup->m_node.chainman->LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent); }); fs::remove(blkfile); } diff --git a/src/bench/streams_findbyte.cpp b/src/bench/streams_findbyte.cpp index b97f130c67..4aaccb2af8 100644 --- a/src/bench/streams_findbyte.cpp +++ b/src/bench/streams_findbyte.cpp @@ -20,7 +20,7 @@ static void FindByte(benchmark::Bench& bench) data[file_size-1] = 1; file << data; std::rewind(file.Get()); - BufferedFile bf{file.Get(), /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0}; + BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size}; bench.run([&] { bf.SetPos(0); -- cgit v1.2.3