From ec431a080f59b0ac46cb18111b3508f1d1f47056 Mon Sep 17 00:00:00 2001 From: Mike Schore Date: Fri, 10 Jul 2020 03:13:57 +0800 Subject: [PATCH] build: minor fix for 32-bit archs (#11726) Fixes an implicit cast error building for 32-bit Android here. Signed-off-by: Mike Schore --- source/common/stats/symbol_table_impl.cc | 41 ++++++++++++------------ source/common/stats/symbol_table_impl.h | 37 ++++++++++----------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/source/common/stats/symbol_table_impl.cc b/source/common/stats/symbol_table_impl.cc index a36a4a2a9681..bf36b088f44e 100644 --- a/source/common/stats/symbol_table_impl.cc +++ b/source/common/stats/symbol_table_impl.cc @@ -31,7 +31,7 @@ static constexpr uint32_t Low7Bits = 0x7f; static constexpr Symbol FirstValidSymbol = 1; static constexpr uint8_t LiteralStringIndicator = 0; -uint64_t StatName::dataSize() const { +size_t StatName::dataSize() const { if (size_and_data_ == nullptr) { return 0; } @@ -46,9 +46,9 @@ void StatName::debugPrint() { if (size_and_data_ == nullptr) { std::cerr << "Null StatName" << std::endl; } else { - const uint64_t nbytes = dataSize(); + const size_t nbytes = dataSize(); std::cerr << "dataSize=" << nbytes << ":"; - for (uint64_t i = 0; i < nbytes; ++i) { + for (size_t i = 0; i < nbytes; ++i) { std::cerr << " " << static_cast(data()[i]); } const SymbolVec encoding = SymbolTableImpl::Encoding::decodeSymbols(data(), dataSize()); @@ -67,8 +67,8 @@ SymbolTableImpl::Encoding::~Encoding() { ASSERT(mem_block_.capacity() == 0); } -uint64_t SymbolTableImpl::Encoding::encodingSizeBytes(uint64_t number) { - uint64_t num_bytes = 0; +size_t SymbolTableImpl::Encoding::encodingSizeBytes(uint64_t number) { + size_t num_bytes = 0; do { ++num_bytes; number >>= 7; @@ -106,7 +106,7 @@ void SymbolTableImpl::Encoding::addSymbols(const std::vector& symbols) { } } -std::pair SymbolTableImpl::Encoding::decodeNumber(const uint8_t* encoding) { +std::pair SymbolTableImpl::Encoding::decodeNumber(const uint8_t* encoding) { uint64_t number = 0; uint64_t uc = SpilloverMask; const uint8_t* start = encoding; @@ -117,8 +117,7 @@ std::pair SymbolTableImpl::Encoding::decodeNumber(const uint return std::make_pair(number, encoding - start); } -SymbolVec SymbolTableImpl::Encoding::decodeSymbols(const SymbolTable::Storage array, - uint64_t size) { +SymbolVec SymbolTableImpl::Encoding::decodeSymbols(const SymbolTable::Storage array, size_t size) { SymbolVec symbol_vec; symbol_vec.reserve(size); decodeTokens( @@ -128,9 +127,9 @@ SymbolVec SymbolTableImpl::Encoding::decodeSymbols(const SymbolTable::Storage ar } void SymbolTableImpl::Encoding::decodeTokens( - const SymbolTable::Storage array, uint64_t size, - const std::function& symbolTokenFn, - const std::function& stringViewTokenFn) { + const SymbolTable::Storage array, size_t size, + const std::function& symbol_token_fn, + const std::function& string_view_token_fn) { while (size > 0) { if (*array == LiteralStringIndicator) { // To avoid scanning memory to find the literal size during decode, we @@ -138,17 +137,17 @@ void SymbolTableImpl::Encoding::decodeTokens( ASSERT(size > 1); ++array; --size; - std::pair length_consumed = decodeNumber(array); + std::pair length_consumed = decodeNumber(array); uint64_t length = length_consumed.first; array += length_consumed.second; size -= length_consumed.second; ASSERT(size >= length); - stringViewTokenFn(absl::string_view(reinterpret_cast(array), length)); + string_view_token_fn(absl::string_view(reinterpret_cast(array), length)); size -= length; array += length; } else { - std::pair symbol_consumed = decodeNumber(array); - symbolTokenFn(symbol_consumed.first); + std::pair symbol_consumed = decodeNumber(array); + symbol_token_fn(symbol_consumed.first); size -= symbol_consumed.second; array += symbol_consumed.second; } @@ -156,7 +155,7 @@ void SymbolTableImpl::Encoding::decodeTokens( } std::vector SymbolTableImpl::decodeStrings(const SymbolTable::Storage array, - uint64_t size) const { + size_t size) const { std::vector strings; Thread::LockGuard lock(lock_); Encoding::decodeTokens( @@ -451,8 +450,8 @@ StatNameStorage::StatNameStorage(absl::string_view name, SymbolTable& table) : StatNameStorageBase(table.encode(name)) {} StatNameStorage::StatNameStorage(StatName src, SymbolTable& table) { - const uint64_t size = src.size(); - MemBlockBuilder storage(size); + const size_t size = src.size(); + MemBlockBuilder storage(size); // Note: MemBlockBuilder takes uint64_t. src.copyToMemBlock(storage); setBytes(storage.release()); table.incRefCount(statName()); @@ -472,11 +471,11 @@ SymbolTable::StoragePtr SymbolTableImpl::makeDynamicStorage(absl::string_view na // payload_bytes is the total number of bytes needed to represent the // characters in name, plus their encoded size, plus the literal indicator. - const uint64_t payload_bytes = SymbolTableImpl::Encoding::totalSizeBytes(name.size()) + 1; + const size_t payload_bytes = SymbolTableImpl::Encoding::totalSizeBytes(name.size()) + 1; // total_bytes includes the payload_bytes, plus the LiteralStringIndicator, and // the length of those. - const uint64_t total_bytes = SymbolTableImpl::Encoding::totalSizeBytes(payload_bytes); + const size_t total_bytes = SymbolTableImpl::Encoding::totalSizeBytes(payload_bytes); MemBlockBuilder mem_block(total_bytes); SymbolTableImpl::Encoding::appendEncoding(payload_bytes, mem_block); @@ -550,7 +549,7 @@ void StatNameStorageSet::free(SymbolTable& symbol_table) { } SymbolTable::StoragePtr SymbolTableImpl::join(const StatNameVec& stat_names) const { - uint64_t num_bytes = 0; + size_t num_bytes = 0; for (StatName stat_name : stat_names) { if (!stat_name.empty()) { num_bytes += stat_name.dataSize(); diff --git a/source/common/stats/symbol_table_impl.h b/source/common/stats/symbol_table_impl.h index f4104fa407e4..7d89b7db8205 100644 --- a/source/common/stats/symbol_table_impl.h +++ b/source/common/stats/symbol_table_impl.h @@ -93,7 +93,7 @@ class SymbolTableImpl : public SymbolTable { /** * Decodes a uint8_t array into a SymbolVec. */ - static SymbolVec decodeSymbols(const SymbolTable::Storage array, uint64_t size); + static SymbolVec decodeSymbols(const SymbolTable::Storage array, size_t size); /** * Decodes a uint8_t array into a sequence of symbols and literal strings. @@ -103,18 +103,18 @@ class SymbolTableImpl : public SymbolTable { * * @param array the StatName encoded as a uint8_t array. * @param size the size of the array in bytes. - * @param symbolTokenFn a function to be called whenever a symbol is encountered in the array. - * @param stringVIewTokeNFn a function to be called whenever a string literal is encountered. + * @param symbol_token_fn a function to be called whenever a symbol is encountered in the array. + * @param string_view_token_fn a function to be called whenever a string literal is encountered. */ - static void decodeTokens(const SymbolTable::Storage array, uint64_t size, - const std::function& symbolTokenFn, - const std::function& stringViewTokenFn); + static void decodeTokens(const SymbolTable::Storage array, size_t size, + const std::function& symbol_token_fn, + const std::function& string_view_token_fn); /** * Returns the number of bytes required to represent StatName as a uint8_t * array, including the encoded size. */ - uint64_t bytesRequired() const { + size_t bytesRequired() const { return data_bytes_required_ + encodingSizeBytes(data_bytes_required_); } @@ -130,13 +130,13 @@ class SymbolTableImpl : public SymbolTable { * @param number A number to encode in a variable length byte-array. * @return The number of bytes it would take to encode the number. */ - static uint64_t encodingSizeBytes(uint64_t number); + static size_t encodingSizeBytes(uint64_t number); /** * @param num_data_bytes The number of bytes in a data-block. * @return The total number of bytes required for the data-block and its encoded size. */ - static uint64_t totalSizeBytes(uint64_t num_data_bytes) { + static size_t totalSizeBytes(size_t num_data_bytes) { return encodingSizeBytes(num_data_bytes) + num_data_bytes; } @@ -167,10 +167,10 @@ class SymbolTableImpl : public SymbolTable { * @param The encoded byte array, written previously by appendEncoding. * @return A pair containing the decoded number, and the number of bytes consumed from encoding. */ - static std::pair decodeNumber(const uint8_t* encoding); + static std::pair decodeNumber(const uint8_t* encoding); private: - uint64_t data_bytes_required_{0}; + size_t data_bytes_required_{0}; MemBlockBuilder mem_block_; }; @@ -229,7 +229,7 @@ class SymbolTableImpl : public SymbolTable { * @param size the size of the array in bytes. * @return std::string the retrieved stat name. */ - std::vector decodeStrings(const Storage array, uint64_t size) const; + std::vector decodeStrings(const Storage array, size_t size) const; /** * Convenience function for encode(), symbolizing one string segment at a time. @@ -403,16 +403,16 @@ class StatName { bool operator!=(const StatName& rhs) const { return !(*this == rhs); } /** - * @return uint64_t the number of bytes in the symbol array, excluding the - * overhead for the size itself. + * @return size_t the number of bytes in the symbol array, excluding the + * overhead for the size itself. */ - uint64_t dataSize() const; + size_t dataSize() const; /** - * @return uint64_t the number of bytes in the symbol array, including the + * @return size_t the number of bytes in the symbol array, including the * overhead for the size itself. */ - uint64_t size() const { return SymbolTableImpl::Encoding::totalSizeBytes(dataSize()); } + size_t size() const { return SymbolTableImpl::Encoding::totalSizeBytes(dataSize()); } /** * Copies the entire StatName representation into a MemBlockBuilder, including @@ -466,7 +466,8 @@ class StatName { * hasher and comparator. */ absl::string_view dataAsStringView() const { - return {reinterpret_cast(data()), dataSize()}; + return {reinterpret_cast(data()), + static_cast(dataSize())}; } const uint8_t* size_and_data_{nullptr};