Skip to content

Commit

Permalink
build: minor fix for 32-bit archs (#11726)
Browse files Browse the repository at this point in the history
Fixes an implicit cast error building for 32-bit Android here.

Signed-off-by: Mike Schore <mike.schore@gmail.com>
  • Loading branch information
goaway authored Jul 9, 2020
1 parent 3b8c61b commit ec431a0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
41 changes: 20 additions & 21 deletions source/common/stats/symbol_table_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<uint64_t>(data()[i]);
}
const SymbolVec encoding = SymbolTableImpl::Encoding::decodeSymbols(data(), dataSize());
Expand All @@ -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;
Expand Down Expand Up @@ -106,7 +106,7 @@ void SymbolTableImpl::Encoding::addSymbols(const std::vector<Symbol>& symbols) {
}
}

std::pair<uint64_t, uint64_t> SymbolTableImpl::Encoding::decodeNumber(const uint8_t* encoding) {
std::pair<uint64_t, size_t> SymbolTableImpl::Encoding::decodeNumber(const uint8_t* encoding) {
uint64_t number = 0;
uint64_t uc = SpilloverMask;
const uint8_t* start = encoding;
Expand All @@ -117,8 +117,7 @@ std::pair<uint64_t, uint64_t> 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(
Expand All @@ -128,35 +127,35 @@ SymbolVec SymbolTableImpl::Encoding::decodeSymbols(const SymbolTable::Storage ar
}

void SymbolTableImpl::Encoding::decodeTokens(
const SymbolTable::Storage array, uint64_t size,
const std::function<void(Symbol)>& symbolTokenFn,
const std::function<void(absl::string_view)>& stringViewTokenFn) {
const SymbolTable::Storage array, size_t size,
const std::function<void(Symbol)>& symbol_token_fn,
const std::function<void(absl::string_view)>& string_view_token_fn) {
while (size > 0) {
if (*array == LiteralStringIndicator) {
// To avoid scanning memory to find the literal size during decode, we
// var-length encode the size of the literal string prior to the data.
ASSERT(size > 1);
++array;
--size;
std::pair<uint64_t, uint64_t> length_consumed = decodeNumber(array);
std::pair<uint64_t, size_t> 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<const char*>(array), length));
string_view_token_fn(absl::string_view(reinterpret_cast<const char*>(array), length));
size -= length;
array += length;
} else {
std::pair<uint64_t, uint64_t> symbol_consumed = decodeNumber(array);
symbolTokenFn(symbol_consumed.first);
std::pair<uint64_t, size_t> symbol_consumed = decodeNumber(array);
symbol_token_fn(symbol_consumed.first);
size -= symbol_consumed.second;
array += symbol_consumed.second;
}
}
}

std::vector<absl::string_view> SymbolTableImpl::decodeStrings(const SymbolTable::Storage array,
uint64_t size) const {
size_t size) const {
std::vector<absl::string_view> strings;
Thread::LockGuard lock(lock_);
Encoding::decodeTokens(
Expand Down Expand Up @@ -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<uint8_t> storage(size);
const size_t size = src.size();
MemBlockBuilder<uint8_t> storage(size); // Note: MemBlockBuilder takes uint64_t.
src.copyToMemBlock(storage);
setBytes(storage.release());
table.incRefCount(statName());
Expand All @@ -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<uint8_t> mem_block(total_bytes);

SymbolTableImpl::Encoding::appendEncoding(payload_bytes, mem_block);
Expand Down Expand Up @@ -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();
Expand Down
37 changes: 19 additions & 18 deletions source/common/stats/symbol_table_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<void(Symbol)>& symbolTokenFn,
const std::function<void(absl::string_view)>& stringViewTokenFn);
static void decodeTokens(const SymbolTable::Storage array, size_t size,
const std::function<void(Symbol)>& symbol_token_fn,
const std::function<void(absl::string_view)>& 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_);
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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<uint64_t, uint64_t> decodeNumber(const uint8_t* encoding);
static std::pair<uint64_t, size_t> decodeNumber(const uint8_t* encoding);

private:
uint64_t data_bytes_required_{0};
size_t data_bytes_required_{0};
MemBlockBuilder<uint8_t> mem_block_;
};

Expand Down Expand Up @@ -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<absl::string_view> decodeStrings(const Storage array, uint64_t size) const;
std::vector<absl::string_view> decodeStrings(const Storage array, size_t size) const;

/**
* Convenience function for encode(), symbolizing one string segment at a time.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -466,7 +466,8 @@ class StatName {
* hasher and comparator.
*/
absl::string_view dataAsStringView() const {
return {reinterpret_cast<const char*>(data()), dataSize()};
return {reinterpret_cast<const char*>(data()),
static_cast<absl::string_view::size_type>(dataSize())};
}

const uint8_t* size_and_data_{nullptr};
Expand Down

0 comments on commit ec431a0

Please sign in to comment.