From: Joel Rosdahl Date: Tue, 6 Jul 2021 07:04:44 +0000 (+0200) Subject: Move READ_BUFFER_SIZE to config.h, adding a CCACHE_ prefix X-Git-Tag: v4.4~148 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b3cee266971d579746ea46468d58db646191c3a8;p=thirdparty%2Fccache.git Move READ_BUFFER_SIZE to config.h, adding a CCACHE_ prefix --- diff --git a/cmake/config.h.in b/cmake/config.h.in index 6014ca611..ed2e19d49 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -1,3 +1,6 @@ +// This file is included by all compilation units, including those in +// src/third_party. It should only contain macros and typedefs. + #pragma once #ifdef __clang__ # pragma clang diagnostic push @@ -186,3 +189,6 @@ typedef unsigned __int32 mode_t; typedef int pid_t; # endif #endif // _WIN32 + +// Buffer size for I/O operations. Should be a multiple of 4 KiB. +#define CCACHE_READ_BUFFER_SIZE 65536 diff --git a/src/Result.cpp b/src/Result.cpp index 3633c2cba..4fd15483e 100644 --- a/src/Result.cpp +++ b/src/Result.cpp @@ -290,7 +290,7 @@ Reader::read_entry(CacheEntryReader& cache_entry_reader, if (marker == k_embedded_file_marker) { consumer.on_entry_start(entry_number, file_type, file_len, nullopt); - uint8_t buf[READ_BUFFER_SIZE]; + uint8_t buf[CCACHE_READ_BUFFER_SIZE]; size_t remain = file_len; while (remain > 0) { size_t n = std::min(remain, sizeof(buf)); @@ -412,7 +412,7 @@ Result::Writer::write_embedded_file_entry(CacheEntryWriter& writer, uint64_t remain = file_size; while (remain > 0) { - uint8_t buf[READ_BUFFER_SIZE]; + uint8_t buf[CCACHE_READ_BUFFER_SIZE]; size_t n = std::min(remain, static_cast(sizeof(buf))); ssize_t bytes_read = read(*file, buf, n); if (bytes_read == -1) { diff --git a/src/Util.cpp b/src/Util.cpp index ed2cb6732..fd701eadc 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -1125,7 +1125,7 @@ bool read_fd(int fd, DataReceiver data_receiver) { ssize_t n; - char buffer[READ_BUFFER_SIZE]; + char buffer[CCACHE_READ_BUFFER_SIZE]; while ((n = read(fd, buffer, sizeof(buffer))) != 0) { if (n == -1 && errno != EINTR) { break; diff --git a/src/ZstdCompressor.cpp b/src/ZstdCompressor.cpp index 39f6bb25c..75c60baca 100644 --- a/src/ZstdCompressor.cpp +++ b/src/ZstdCompressor.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -80,7 +80,7 @@ ZstdCompressor::write(const void* data, size_t count) size_t ret; while (m_zstd_in.pos < m_zstd_in.size) { - uint8_t buffer[READ_BUFFER_SIZE]; + uint8_t buffer[CCACHE_READ_BUFFER_SIZE]; m_zstd_out.dst = buffer; m_zstd_out.size = sizeof(buffer); m_zstd_out.pos = 0; @@ -94,7 +94,7 @@ ZstdCompressor::write(const void* data, size_t count) } ret = flush; while (ret > 0) { - uint8_t buffer[READ_BUFFER_SIZE]; + uint8_t buffer[CCACHE_READ_BUFFER_SIZE]; m_zstd_out.dst = buffer; m_zstd_out.size = sizeof(buffer); m_zstd_out.pos = 0; diff --git a/src/ZstdDecompressor.hpp b/src/ZstdDecompressor.hpp index 80533c181..4c79886b4 100644 --- a/src/ZstdDecompressor.hpp +++ b/src/ZstdDecompressor.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -41,7 +41,7 @@ public: private: FILE* m_stream; - char m_input_buffer[READ_BUFFER_SIZE]; + char m_input_buffer[CCACHE_READ_BUFFER_SIZE]; size_t m_input_size; size_t m_input_consumed; ZSTD_DStream* m_zstd_stream; diff --git a/src/compress.cpp b/src/compress.cpp index 157df6a0f..70c711762 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -180,7 +180,7 @@ recompress_file(RecompressionStatistics& statistics, level ? Compression::Type::zstd : Compression::Type::none, wanted_level); - char buffer[READ_BUFFER_SIZE]; + char buffer[CCACHE_READ_BUFFER_SIZE]; size_t bytes_left = reader->payload_size(); while (bytes_left > 0) { size_t bytes_to_read = std::min(bytes_left, sizeof(buffer)); diff --git a/src/system.hpp b/src/system.hpp index 99fe9287c..df71a6d1a 100644 --- a/src/system.hpp +++ b/src/system.hpp @@ -78,9 +78,6 @@ extern "C" int usleep(useconds_t); #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) -// Buffer size for I/O operations. Should be a multiple of 4 KiB. -const size_t READ_BUFFER_SIZE = 65536; - #ifndef ESTALE # define ESTALE -1 #endif