diff --git a/libs/EXTERNAL/libblifparse/CMakeLists.txt b/libs/EXTERNAL/libblifparse/CMakeLists.txt index 714c54d775f..57f33eb2e57 100644 --- a/libs/EXTERNAL/libblifparse/CMakeLists.txt +++ b/libs/EXTERNAL/libblifparse/CMakeLists.txt @@ -45,6 +45,10 @@ add_library(libblifparse STATIC target_include_directories(libblifparse PUBLIC ${LIB_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) set_target_properties(libblifparse PROPERTIES PREFIX "") #Avoid extra 'lib' prefix +# Set the read buffer size in the generated lexers. This reduces the number of +# syscalls since the default is only 1kB. +target_compile_definitions(libblifparse PRIVATE YY_READ_BUF_SIZE=1048576) + #Create the test executable add_executable(blifparse_test src/main.cpp) target_link_libraries(blifparse_test libblifparse) diff --git a/libs/libpugiutil/src/pugixml_loc.cpp b/libs/libpugiutil/src/pugixml_loc.cpp index b773b410b53..138b7f39903 100644 --- a/libs/libpugiutil/src/pugixml_loc.cpp +++ b/libs/libpugiutil/src/pugixml_loc.cpp @@ -1,8 +1,14 @@ #include #include +#include #include "pugixml_util.hpp" #include "pugixml_loc.hpp" +// The size of the read buffer when reading from a file. +#ifndef PUGI_UTIL_READ_BUF_SIZE +#define PUGI_UTIL_READ_BUF_SIZE 1048576 +#endif // PUGI_UTIL_READ_BUF_SIZE + namespace pugiutil { //Return the line number from the given offset @@ -30,10 +36,10 @@ void loc_data::build_loc_data() { std::ptrdiff_t offset = 0; - char buffer[1024]; + std::vector buffer(PUGI_UTIL_READ_BUF_SIZE); std::size_t size; - while ((size = fread(buffer, 1, sizeof(buffer), f)) > 0) { + while ((size = fread(buffer.data(), 1, buffer.size() * sizeof(char), f)) > 0) { for (std::size_t i = 0; i < size; ++i) { if (buffer[i] == '\n') { offsets_.push_back(offset + i); diff --git a/libs/libvtrutil/src/vtr_digest.cpp b/libs/libvtrutil/src/vtr_digest.cpp index aedcd613ecb..d5d90f12c45 100644 --- a/libs/libvtrutil/src/vtr_digest.cpp +++ b/libs/libvtrutil/src/vtr_digest.cpp @@ -3,10 +3,15 @@ #include #include -#include +#include #include "picosha2.h" +// The size of the read buffer when reading from a file. +#ifndef VTR_UTIL_READ_BUF_SIZE +#define VTR_UTIL_READ_BUF_SIZE 1048576 +#endif // VTR_UTIL_READ_BUF_SIZE + namespace vtr { std::string secure_digest_file(const std::string& filepath) { @@ -21,7 +26,7 @@ std::string secure_digest_stream(std::istream& is) { //Read the stream in chunks and calculate the SHA256 digest picosha2::hash256_one_by_one hasher; - std::array buf; + std::vector buf(VTR_UTIL_READ_BUF_SIZE); while (!is.eof()) { //Process a chunk is.read(buf.data(), buf.size());