From 4074db5f50f29e57d31f195e73b68afa1113c80e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 7 Dec 2021 11:49:59 +0100 Subject: [PATCH] io/BufferedReader: use std::size_t --- src/io/BufferedReader.cxx | 11 ++++++----- src/io/BufferedReader.hxx | 8 ++++---- src/io/OutputStream.hxx | 2 +- src/io/Reader.hxx | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/io/BufferedReader.cxx b/src/io/BufferedReader.cxx index 4a67af42c..5808cd419 100644 --- a/src/io/BufferedReader.cxx +++ b/src/io/BufferedReader.cxx @@ -31,6 +31,7 @@ #include "Reader.hxx" #include "util/TextFile.hxx" +#include #include #include @@ -52,7 +53,7 @@ BufferedReader::Fill(bool need_more) assert(!w.empty()); } - size_t nbytes = reader.Read(w.data, w.size); + std::size_t nbytes = reader.Read(w.data, w.size); if (nbytes == 0) { eof = true; return !need_more; @@ -63,7 +64,7 @@ BufferedReader::Fill(bool need_more) } void * -BufferedReader::ReadFull(size_t size) +BufferedReader::ReadFull(std::size_t size) { while (true) { auto r = Read(); @@ -75,11 +76,11 @@ BufferedReader::ReadFull(size_t size) } } -size_t +std::size_t BufferedReader::ReadFromBuffer(WritableBuffer dest) noexcept { auto src = Read(); - size_t nbytes = std::min(src.size, dest.size); + std::size_t nbytes = std::min(src.size, dest.size); memcpy(dest.data, src.data, nbytes); Consume(nbytes); return nbytes; @@ -92,7 +93,7 @@ BufferedReader::ReadFull(WritableBuffer _dest) assert(dest.size == _dest.size); while (true) { - size_t nbytes = ReadFromBuffer(dest.ToVoid()); + std::size_t nbytes = ReadFromBuffer(dest.ToVoid()); dest.skip_front(nbytes); if (dest.size == 0) break; diff --git a/src/io/BufferedReader.hxx b/src/io/BufferedReader.hxx index bfad2b602..4ecc7f8cb 100644 --- a/src/io/BufferedReader.hxx +++ b/src/io/BufferedReader.hxx @@ -37,7 +37,7 @@ class Reader; class BufferedReader { - static constexpr size_t MAX_SIZE = 512 * 1024; + static constexpr std::size_t MAX_SIZE = 512 * 1024; Reader &reader; @@ -73,9 +73,9 @@ public: * it). Throws std::runtime_error if not enough data is * available. */ - void *ReadFull(size_t size); + void *ReadFull(std::size_t size); - void Consume(size_t n) noexcept { + void Consume(std::size_t n) noexcept { buffer.Consume(n); } @@ -83,7 +83,7 @@ public: * Read (and consume) data from the input buffer into the * given buffer. Does not attempt to refill the buffer. */ - size_t ReadFromBuffer(WritableBuffer dest) noexcept; + std::size_t ReadFromBuffer(WritableBuffer dest) noexcept; /** * Read data into the given buffer and consume it from our diff --git a/src/io/OutputStream.hxx b/src/io/OutputStream.hxx index 465af8b96..c9ea7cbd5 100644 --- a/src/io/OutputStream.hxx +++ b/src/io/OutputStream.hxx @@ -40,7 +40,7 @@ public: /** * Throws std::exception on error. */ - virtual void Write(const void *data, size_t size) = 0; + virtual void Write(const void *data, std::size_t size) = 0; }; #endif diff --git a/src/io/Reader.hxx b/src/io/Reader.hxx index 44fec1fad..bc9387875 100644 --- a/src/io/Reader.hxx +++ b/src/io/Reader.hxx @@ -51,7 +51,7 @@ public: * on end-of-stream */ [[gnu::nonnull]] - virtual size_t Read(void *data, size_t size) = 0; + virtual std::size_t Read(void *data, std::size_t size) = 0; }; #endif