diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-07 10:17:19 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-07 10:18:12 +0100 |
commit | 9eacfe4fcb48e0cb3c6897d3b4216f5303100f39 (patch) | |
tree | d84a4e584d473b1e5f55f0f0fc9d1f9f2f0763e7 /common | |
parent | wsd: can avoid copying these in AdminModel (diff) | |
download | online-9eacfe4fcb48e0cb3c6897d3b4216f5303100f39.tar.gz online-9eacfe4fcb48e0cb3c6897d3b4216f5303100f39.zip |
common: spell out non-trivial autos to improve readability
Change-Id: Id13bc0e48cec845f5b05171128be5b4efc05c6bc
Diffstat (limited to 'common')
-rw-r--r-- | common/Common.hpp | 12 | ||||
-rw-r--r-- | common/FileUtil.cpp | 2 | ||||
-rw-r--r-- | common/IoUtil.cpp | 12 | ||||
-rw-r--r-- | common/Message.hpp | 8 | ||||
-rw-r--r-- | common/MessageQueue.cpp | 22 | ||||
-rw-r--r-- | common/MessageQueue.hpp | 6 | ||||
-rw-r--r-- | common/Png.hpp | 2 | ||||
-rw-r--r-- | common/Protocol.cpp | 6 | ||||
-rw-r--r-- | common/Protocol.hpp | 16 | ||||
-rw-r--r-- | common/Session.cpp | 2 | ||||
-rw-r--r-- | common/SigUtil.cpp | 4 | ||||
-rw-r--r-- | common/Util.cpp | 10 | ||||
-rw-r--r-- | common/Util.hpp | 12 |
13 files changed, 57 insertions, 57 deletions
diff --git a/common/Common.hpp b/common/Common.hpp index b58c2ca752..b73e982494 100644 --- a/common/Common.hpp +++ b/common/Common.hpp @@ -29,16 +29,16 @@ constexpr long READ_BUFFER_SIZE = 64 * 1024; /// or as intentionally flooding the server. constexpr int MAX_MESSAGE_SIZE = 2 * 1024 * READ_BUFFER_SIZE; -constexpr auto JAILED_DOCUMENT_ROOT = "/user/docs/"; -constexpr auto CHILD_URI = "/loolws/child?"; -constexpr auto NEW_CHILD_URI = "/loolws/newchild?"; -constexpr auto LO_JAIL_SUBPATH = "lo"; +constexpr const char* JAILED_DOCUMENT_ROOT = "/user/docs/"; +constexpr const char* CHILD_URI = "/loolws/child?"; +constexpr const char* NEW_CHILD_URI = "/loolws/newchild?"; +constexpr const char* LO_JAIL_SUBPATH = "lo"; /// The HTTP response User-Agent. -constexpr auto HTTP_AGENT_STRING = "LOOLWSD HTTP Agent " LOOLWSD_VERSION; +constexpr const char* HTTP_AGENT_STRING = "LOOLWSD HTTP Agent " LOOLWSD_VERSION; /// The WOPI User-Agent. -constexpr auto WOPI_AGENT_STRING = "LOOLWSD WOPI Agent " LOOLWSD_VERSION; +constexpr const char* WOPI_AGENT_STRING = "LOOLWSD WOPI Agent " LOOLWSD_VERSION; // The client port number, both loolwsd and the kits have this. extern int ClientPortNumber; diff --git a/common/FileUtil.cpp b/common/FileUtil.cpp index afb0395ec5..212cf7e82c 100644 --- a/common/FileUtil.cpp +++ b/common/FileUtil.cpp @@ -42,7 +42,7 @@ namespace FileUtil { std::string createRandomDir(const std::string& path) { - const auto name = Util::rng::getFilename(64); + const std::string name = Util::rng::getFilename(64); Poco::File(Poco::Path(path, name)).createDirectories(); return name; } diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp index 58fc274e1a..b1ee058a51 100644 --- a/common/IoUtil.cpp +++ b/common/IoUtil.cpp @@ -146,7 +146,7 @@ void SocketProcessor(const std::shared_ptr<LOOLWebSocket>& ws, LOG_CHECK(n > 0); // Call the handler. - const auto success = handler(payload); + const bool success = handler(payload); payload.resize(0); if (!success) @@ -188,7 +188,7 @@ ssize_t writeToPipe(int pipe, const char* buffer, ssize_t size) for (;;) { LOG_TRC("Writing to pipe. Data: [" << Util::formatLinesForLog(std::string(buffer, size)) << "]."); - const auto bytes = write(pipe, buffer + count, size - count); + const ssize_t bytes = write(pipe, buffer + count, size - count); if (bytes < 0) { if (errno == EINTR || errno == EAGAIN) @@ -244,8 +244,8 @@ int PipeReader::readLine(std::string& line, } // Poll in short intervals to check for stop condition. - const auto pollTimeoutMs = 500; - auto maxPollCount = std::max<int>(POLL_TIMEOUT_MS / pollTimeoutMs, 1); + const int pollTimeoutMs = 500; + int maxPollCount = std::max<int>(POLL_TIMEOUT_MS / pollTimeoutMs, 1); while (maxPollCount-- > 0) { if (stopPredicate()) @@ -277,7 +277,7 @@ int PipeReader::readLine(std::string& line, else if (pipe.revents & (POLLIN | POLLPRI)) { char buffer[READ_BUFFER_SIZE]; - const auto bytes = readFromPipe(_pipe, buffer, sizeof(buffer)); + const ssize_t bytes = readFromPipe(_pipe, buffer, sizeof(buffer)); LOG_TRC("readFromPipe for pipe: " << _name << " returned: " << bytes); if (bytes < 0) { @@ -289,7 +289,7 @@ int PipeReader::readLine(std::string& line, { // Got end of line. line = _data; - const auto tail = std::string(static_cast<const char*>(buffer), endOfLine); + const std::string tail(static_cast<const char*>(buffer), endOfLine); line += tail; _data = std::string(endOfLine + 1, bytes - tail.size() - 1); // Exclude the '\n'. LOG_TRC("Read line from pipe: " << _name << ", line: [" << line << diff --git a/common/Message.hpp b/common/Message.hpp index cfca3f81b6..a62cfe3750 100644 --- a/common/Message.hpp +++ b/common/Message.hpp @@ -55,7 +55,7 @@ public: _type(detectType()) { _data.resize(message.size()); - const auto offset = skipWhitespace(message.data() + _forwardToken.size()); + const char* offset = skipWhitespace(message.data() + _forwardToken.size()); std::memcpy(_data.data(), offset, message.size() - (offset - message.data())); LOG_TRC("Message " << _abbr); } @@ -99,7 +99,7 @@ public: { if (_tokens.size() > 1 && _tokens[1] == "{") { - const auto firstTokenSize = _tokens[0].size(); + const size_t firstTokenSize = _tokens[0].size(); return std::string(_data.data() + firstTokenSize, _data.size() - firstTokenSize); } @@ -109,7 +109,7 @@ public: /// Append more data to the message. void append(const char* p, const size_t len) { - const auto curSize = _data.size(); + const size_t curSize = _data.size(); _data.resize(curSize + len); std::memcpy(_data.data() + curSize, p, len); } @@ -147,7 +147,7 @@ private: std::string getForwardToken(const char* buffer, int length) { - auto forward = LOOLProtocol::getFirstToken(buffer, length); + std::string forward = LOOLProtocol::getFirstToken(buffer, length); return (forward.find('-') != std::string::npos ? forward : std::string()); } diff --git a/common/MessageQueue.cpp b/common/MessageQueue.cpp index 1f1d805f35..5322db2c3f 100644 --- a/common/MessageQueue.cpp +++ b/common/MessageQueue.cpp @@ -26,13 +26,13 @@ using Poco::StringTokenizer; void TileQueue::put_impl(const Payload& value) { - const auto msg = std::string(value.data(), value.size()); + const std::string msg = std::string(value.data(), value.size()); const std::string firstToken = LOOLProtocol::getFirstToken(value); if (firstToken == "canceltiles") { LOG_TRC("Processing [" << msg << "]. Before canceltiles have " << _queue.size() << " in queue."); - const auto seqs = msg.substr(12); + const std::string seqs = msg.substr(12); StringTokenizer tokens(seqs, ",", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); _queue.erase(std::remove_if(_queue.begin(), _queue.end(), [&tokens](const Payload& v) @@ -62,7 +62,7 @@ void TileQueue::put_impl(const Payload& value) { // Breakup tilecombine and deduplicate (we are re-combining the tiles // in the get_impl() again) - const auto tileCombined = TileCombined::parse(msg); + const TileCombined tileCombined = TileCombined::parse(msg); for (auto& tile : tileCombined.getTiles()) { const std::string newMsg = tile.serialize("tile"); @@ -107,7 +107,7 @@ void TileQueue::removeTileDuplicate(const std::string& tileMsg) // return back to clients the last rendered version of a tile // in case there are new invalidations and requests while rendering. // Here we compare duplicates without 'ver' since that's irrelevant. - auto newMsgPos = tileMsg.find(" ver"); + size_t newMsgPos = tileMsg.find(" ver"); if (newMsgPos == std::string::npos) { newMsgPos = tileMsg.size() - 1; @@ -135,7 +135,7 @@ std::string extractViewId(const std::string& origMsg, const std::vector<std::str std::string jsonString(origMsg.data() + nonJson, origMsg.size() - nonJson); Poco::JSON::Parser parser; - const auto result = parser.parse(jsonString); + const Poco::Dynamic::Var result = parser.parse(jsonString); const auto& json = result.extract<Poco::JSON::Object::Ptr>(); return json->get("viewId").toString(); } @@ -395,7 +395,7 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg) int TileQueue::priority(const std::string& tileMsg) { - auto tile = TileDesc::parse(tileMsg); //FIXME: Expensive, avoid. + TileDesc tile = TileDesc::parse(tileMsg); //FIXME: Expensive, avoid. for (int i = static_cast<int>(_viewOrder.size()) - 1; i >= 0; --i) { @@ -411,7 +411,7 @@ void TileQueue::deprioritizePreviews() { for (size_t i = 0; i < _queue.size(); ++i) { - const auto front = _queue.front(); + const Payload front = _queue.front(); const std::string message(front.data(), front.size()); // stop at the first non-tile or non-'id' (preview) message @@ -431,9 +431,9 @@ TileQueue::Payload TileQueue::get_impl() { LOG_TRC("MessageQueue depth: " << _queue.size()); - const auto front = _queue.front(); + const Payload front = _queue.front(); - auto msg = std::string(front.data(), front.size()); + std::string msg(front.data(), front.size()); std::string id; bool isTile = LOOLProtocol::matchPrefix("tile", msg); @@ -503,7 +503,7 @@ TileQueue::Payload TileQueue::get_impl() continue; } - auto tile2 = TileDesc::parse(msg); + TileDesc tile2 = TileDesc::parse(msg); LOG_TRC("Combining candidate: " << msg); // Check if it's on the same row. @@ -527,7 +527,7 @@ TileQueue::Payload TileQueue::get_impl() return Payload(msg.data(), msg.data() + msg.size()); } - auto tileCombined = TileCombined::create(tiles).serialize("tilecombine"); + std::string tileCombined = TileCombined::create(tiles).serialize("tilecombine"); LOG_TRC("MessageQueue res: " << tileCombined); return Payload(tileCombined.data(), tileCombined.data() + tileCombined.size()); } diff --git a/common/MessageQueue.hpp b/common/MessageQueue.hpp index c3ae0e21b9..14c448c2af 100644 --- a/common/MessageQueue.hpp +++ b/common/MessageQueue.hpp @@ -148,9 +148,9 @@ private: public: void updateCursorPosition(int viewId, int part, int x, int y, int width, int height) { - const auto cursorPosition = CursorPosition({ part, x, y, width, height }); + const TileQueue::CursorPosition cursorPosition = CursorPosition({ part, x, y, width, height }); - auto lock = getLock(); + std::unique_lock<std::mutex> lock = getLock(); auto it = _cursorPositions.lower_bound(viewId); if (it != _cursorPositions.end() && it->first == viewId) @@ -175,7 +175,7 @@ public: void removeCursorPosition(int viewId) { - auto lock = getLock(); + std::unique_lock<std::mutex> lock = getLock(); const auto view = std::find(_viewOrder.begin(), _viewOrder.end(), viewId); if (view != _viewOrder.end()) diff --git a/common/Png.hpp b/common/Png.hpp index f682772f74..921792acf1 100644 --- a/common/Png.hpp +++ b/common/Png.hpp @@ -247,7 +247,7 @@ std::vector<png_bytep> decodePNG(std::stringstream& stream, png_uint_32& height, // rows for (png_uint_32 itRow = 0; itRow < height; itRow++) { - const auto index = height + (itRow * rowBytes + sizeof(png_bytep) - 1) / sizeof(png_bytep); + const size_t index = height + (itRow * rowBytes + sizeof(png_bytep) - 1) / sizeof(png_bytep); rows[itRow] = reinterpret_cast<png_bytep>(&rows[index]); } diff --git a/common/Protocol.cpp b/common/Protocol.cpp index a4c089b297..6ab965e185 100644 --- a/common/Protocol.cpp +++ b/common/Protocol.cpp @@ -214,14 +214,14 @@ namespace LOOLProtocol { if (message.size() > name.size() + 1) { - auto pos = message.find(name); + size_t pos = message.find(name); while (pos != std::string::npos) { bool spaceBefore = pos == 0 || message[pos-1] == ' '; - const auto beg = pos + name.size(); + const size_t beg = pos + name.size(); if (spaceBefore && message[beg] == '=') { - const auto end = message.find_first_of(" \n", beg); + const size_t end = message.find_first_of(" \n", beg); value = message.substr(beg + 1, end - beg - 1); return true; } diff --git a/common/Protocol.hpp b/common/Protocol.hpp index 1e2158a918..61f35b71c9 100644 --- a/common/Protocol.hpp +++ b/common/Protocol.hpp @@ -48,7 +48,7 @@ namespace LOOLProtocol inline bool parseNameValuePair(const std::string& token, std::string& name, std::string& value, const char delim = '=') { - const auto mid = token.find_first_of(delim); + const size_t mid = token.find_first_of(delim); if (mid != std::string::npos) { name = token.substr(0, mid); @@ -149,7 +149,7 @@ namespace LOOLProtocol if (message && length > 0) { const char *founddelim = static_cast<const char *>(std::memchr(message, delim, length)); - const auto size = (founddelim == nullptr ? length : founddelim - message); + const size_t size = (founddelim == nullptr ? length : founddelim - message); return size; } @@ -159,7 +159,7 @@ namespace LOOLProtocol inline std::string getDelimitedInitialSubstring(const char *message, const int length, const char delim) { - const auto size = getDelimiterPosition(message, length, delim); + const size_t size = getDelimiterPosition(message, length, delim); return std::string(message, size); } @@ -167,7 +167,7 @@ namespace LOOLProtocol inline std::pair<std::string, std::string> split(const char* s, const int length, const char delimeter = ' ') { - const auto size = getDelimiterPosition(s, length, delimeter); + const size_t size = getDelimiterPosition(s, length, delimeter); return std::make_pair(std::string(s, size), std::string(s+size+1)); } @@ -210,8 +210,8 @@ namespace LOOLProtocol { if (ignoreWhitespace) { - const auto posPre = prefix.find_first_not_of(' '); - const auto posMsg = message.find_first_not_of(' '); + const size_t posPre = prefix.find_first_not_of(' '); + const size_t posMsg = message.find_first_not_of(' '); return matchPrefix(posPre == std::string::npos ? prefix : prefix.substr(posPre), posMsg == std::string::npos ? message : message.substr(posMsg)); @@ -269,7 +269,7 @@ namespace LOOLProtocol return std::string(); } - const auto firstLine = getFirstLine(message, std::min(length, 500)); + const std::string firstLine = getFirstLine(message, std::min(length, 500)); // If first line is less than the length (minus newline), add ellipsis. if (firstLine.size() < static_cast<std::string::size_type>(length) - 1) @@ -282,7 +282,7 @@ namespace LOOLProtocol inline std::string getAbbreviatedMessage(const std::string& message) { - const auto pos = getDelimiterPosition(message.data(), std::min(message.size(), 500UL), '\n'); + const size_t pos = getDelimiterPosition(message.data(), std::min(message.size(), 500UL), '\n'); // If first line is less than the length (minus newline), add ellipsis. if (pos < static_cast<std::string::size_type>(message.size()) - 1) diff --git a/common/Session.cpp b/common/Session.cpp index 0a9f9c3abb..d507bcf0e1 100644 --- a/common/Session.cpp +++ b/common/Session.cpp @@ -214,7 +214,7 @@ void Session::handleMessage(bool /*fin*/, WSOpCode /*code*/, std::vector<char> & void Session::getIOStats(uint64_t &sent, uint64_t &recv) { - auto socket = _socket.lock(); + std::shared_ptr<StreamSocket> socket = _socket.lock(); if (socket) socket->getIOStats(sent, recv); else diff --git a/common/SigUtil.cpp b/common/SigUtil.cpp index e2e5d51855..856e89fd53 100644 --- a/common/SigUtil.cpp +++ b/common/SigUtil.cpp @@ -295,8 +295,8 @@ namespace SigUtil LOG_SYS("Error when trying to kill PID: " << pid << ". Will wait for termination."); - const auto sleepMs = 50; - const auto count = std::max(CHILD_REBALANCE_INTERVAL_MS / sleepMs, 2); + const int sleepMs = 50; + const int count = std::max(CHILD_REBALANCE_INTERVAL_MS / sleepMs, 2); for (int i = 0; i < count; ++i) { if (kill(pid, 0) == 0 || errno == ESRCH) diff --git a/common/Util.cpp b/common/Util.cpp index 3c3c7897df..7605c5a398 100644 --- a/common/Util.cpp +++ b/common/Util.cpp @@ -335,7 +335,7 @@ namespace Util std::string getMemoryStats(FILE* file) { - const auto pssAndDirtyKb = getPssAndDirtyFromSMaps(file); + const std::pair<size_t, size_t> pssAndDirtyKb = getPssAndDirtyFromSMaps(file); std::ostringstream oss; oss << "procmemstats: pid=" << getpid() << " pss=" << pssAndDirtyKb.first @@ -352,7 +352,7 @@ namespace Util FILE* fp = fopen(cmd.c_str(), "r"); if (fp != nullptr) { - const auto pss = getPssAndDirtyFromSMaps(fp).first; + const size_t pss = getPssAndDirtyFromSMaps(fp).first; fclose(fp); return pss; } @@ -363,7 +363,7 @@ namespace Util size_t getMemoryUsageRSS(const Poco::Process::PID pid) { - static const auto pageSizeBytes = getpagesize(); + static const int pageSizeBytes = getpagesize(); size_t rss = 0; if (pid > 0) @@ -401,7 +401,7 @@ namespace Util { const std::string s(line); int index = 1; - auto pos = s.find(' '); + size_t pos = s.find(' '); while (pos != std::string::npos) { if (index == ind) @@ -501,7 +501,7 @@ namespace Util std::map<std::string, std::string> JsonToMap(const std::string& jsonString) { Poco::JSON::Parser parser; - const auto result = parser.parse(jsonString); + const Poco::Dynamic::Var result = parser.parse(jsonString); const auto& json = result.extract<Poco::JSON::Object::Ptr>(); std::vector<std::string> names; diff --git a/common/Util.hpp b/common/Util.hpp index a51e402ee3..2f58318537 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -212,7 +212,7 @@ namespace Util /// Trim spaces from the left. Just spaces. inline std::string& ltrim(std::string& s) { - const auto pos = s.find_first_not_of(' '); + const size_t pos = s.find_first_not_of(' '); if (pos != std::string::npos) { s = s.substr(pos); @@ -224,7 +224,7 @@ namespace Util /// Trim spaces from the left and copy. Just spaces. inline std::string ltrimmed(const std::string& s) { - const auto pos = s.find_first_not_of(' '); + const size_t pos = s.find_first_not_of(' '); if (pos != std::string::npos) { return s.substr(pos); @@ -236,8 +236,8 @@ namespace Util /// Trim spaces from both left and right. Just spaces. inline std::string& trim(std::string& s) { - const auto first = s.find_first_not_of(' '); - const auto last = s.find_last_not_of(' '); + const size_t first = s.find_first_not_of(' '); + const size_t last = s.find_last_not_of(' '); if (first != std::string::npos) { if (last != std::string::npos) @@ -267,8 +267,8 @@ namespace Util /// Trim spaces from both left and right and copy. Just spaces. inline std::string trimmed(const std::string& s) { - const auto first = s.find_first_not_of(' '); - const auto last = s.find_last_not_of(' '); + const size_t first = s.find_first_not_of(' '); + const size_t last = s.find_last_not_of(' '); if (first != std::string::npos) { if (last != std::string::npos) |