Commit 3de8f357 authored by Rosen Penev's avatar Rosen Penev Committed by Facebook Github Bot

Use auto where appropriate (#1256)

Summary:
Found with modernize-use-auto
Signed-off-by: default avatarRosen Penev <rosenp@gmail.com>
Pull Request resolved: https://github.com/facebook/folly/pull/1256

Reviewed By: Orvid

Differential Revision: D18421629

Pulled By: yfeldblum

fbshipit-source-id: c49418a3b3413acd1506c550af44c806332eedb8
parent 99b49e47
......@@ -276,7 +276,7 @@ Expected<bool, ConversionCode> str_to_bool(StringPiece* src) noexcept {
}
bool result;
size_t len = size_t(e - b);
auto len = size_t(e - b);
switch (*b) {
case '0':
case '1': {
......@@ -400,7 +400,7 @@ Expected<Tgt, ConversionCode> str_to_floating(StringPiece* src) noexcept {
// There must be non-whitespace, otherwise we would have caught this above
assert(b < e);
size_t size = size_t(e - b);
auto size = size_t(e - b);
bool negative = false;
if (*b == '-') {
......@@ -544,7 +544,7 @@ inline Expected<Tgt, ConversionCode> digits_to(
return makeUnexpected(err);
}
size_t size = size_t(e - b);
auto size = size_t(e - b);
/* Although the string is entirely made of digits, we still need to
* check for overflow.
......
......@@ -270,7 +270,7 @@ void FormatArg::initSlow() {
}
Sign s;
unsigned char uSign = static_cast<unsigned char>(*p);
auto uSign = static_cast<unsigned char>(*p);
if ((s = formatSignTable[uSign]) != Sign::INVALID) {
sign = s;
if (++p == end) {
......@@ -391,7 +391,7 @@ void FormatArg::validate(Type type) const {
namespace detail {
void insertThousandsGroupingUnsafe(char* start_buffer, char** end_buffer) {
uint32_t remaining_digits = uint32_t(*end_buffer - start_buffer);
auto remaining_digits = uint32_t(*end_buffer - start_buffer);
uint32_t separator_size = (remaining_digits - 1) / 3;
uint32_t result_size = remaining_digits + separator_size;
*end_buffer = *end_buffer + separator_size;
......
......@@ -246,12 +246,12 @@ IPAddress::IPAddress(const sockaddr* addr) : addr_(), family_(AF_UNSPEC) {
family_ = addr->sa_family;
switch (addr->sa_family) {
case AF_INET: {
const sockaddr_in* v4addr = reinterpret_cast<const sockaddr_in*>(addr);
auto v4addr = reinterpret_cast<const sockaddr_in*>(addr);
addr_.ipV4Addr = IPAddressV4(v4addr->sin_addr);
break;
}
case AF_INET6: {
const sockaddr_in6* v6addr = reinterpret_cast<const sockaddr_in6*>(addr);
auto v6addr = reinterpret_cast<const sockaddr_in6*>(addr);
addr_.ipV6Addr = IPAddressV6(*v6addr);
break;
}
......
......@@ -339,7 +339,7 @@ void SocketAddress::setFromSockaddr(
// Fill the rest with 0s, just for safety
if (addrlen < sizeof(struct sockaddr_un)) {
char* p = reinterpret_cast<char*>(storage_.un.addr);
auto p = reinterpret_cast<char*>(storage_.un.addr);
memset(p + addrlen, 0, sizeof(struct sockaddr_un) - addrlen);
}
}
......
......@@ -416,7 +416,7 @@ std::string prettyPrint(double val, PrettyType type, bool addSpace) {
double prettyToDouble(
folly::StringPiece* const prettyString,
const PrettyType type) {
double value = folly::to<double>(prettyString);
auto value = folly::to<double>(prettyString);
while (prettyString->size() > 0 && std::isspace(prettyString->front())) {
prettyString->advance(1); // Skipping spaces between number and suffix
}
......@@ -542,7 +542,7 @@ void toLowerAscii8(char& c) {
// by adding 0x20.
// Step 1: Clear the high order bit. We'll deal with it in Step 5.
uint8_t rotated = uint8_t(c & 0x7f);
auto rotated = uint8_t(c & 0x7f);
// Currently, the value of rotated, as a function of the original c is:
// below 'A': 0- 64
// 'A'-'Z': 65- 90
......@@ -631,7 +631,7 @@ void toLowerAscii(char* str, size_t length) {
// Convert a character at a time until we reach an address that
// is at least 32-bit aligned
size_t n = (size_t)str;
auto n = (size_t)str;
n &= kAlignMask32;
n = std::min(n, length);
size_t offset = 0;
......
......@@ -386,7 +386,7 @@ void Subprocess::spawnInternal(
// Note that the const casts below are legit, per
// http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html
char** argVec = const_cast<char**>(argv.get());
auto argVec = const_cast<char**>(argv.get());
// Set up environment
std::unique_ptr<const char*[]> envHolder;
......
......@@ -2111,7 +2111,7 @@ constexpr Factory
};
Factory const& getFactory(CodecType type) {
size_t const idx = static_cast<size_t>(type);
auto const idx = static_cast<size_t>(type);
if (idx >= static_cast<size_t>(CodecType::NUM_CODEC_TYPES)) {
throw std::invalid_argument(
to<std::string>("Compression type ", idx, " invalid"));
......
......@@ -59,7 +59,7 @@ std::size_t tlsMinstdRand(std::size_t n) {
FOLLY_SAFE_DCHECK(n > 0, "");
static FOLLY_F14_DETAIL_TLS_SIZE_T state{0};
uint32_t s = static_cast<uint32_t>(state);
auto s = static_cast<uint32_t>(state);
if (s == 0) {
uint64_t seed = static_cast<uint64_t>(
std::chrono::steady_clock::now().time_since_epoch().count());
......
......@@ -70,10 +70,10 @@ std::unique_ptr<char*, void (*)(char**)> EnvironmentState::toPointerArray()
}
size_t allocationRequired =
(totalStringLength / sizeof(char*) + 1) + env_.size() + 1;
char** raw = new char*[allocationRequired];
auto raw = new char*[allocationRequired];
char** ptrBase = raw;
char* stringBase = reinterpret_cast<char*>(&raw[env_.size() + 1]);
char* const stringEnd = reinterpret_cast<char*>(&raw[allocationRequired]);
auto stringBase = reinterpret_cast<char*>(&raw[env_.size() + 1]);
auto const stringEnd = reinterpret_cast<char*>(&raw[allocationRequired]);
for (auto const& pair : env_) {
std::string const& key = pair.first;
std::string const& value = pair.second;
......
......@@ -73,7 +73,7 @@ class HugePageArena {
void* reserve(size_t size, size_t alignment);
bool addressInArena(void* address) {
uintptr_t addr = reinterpret_cast<uintptr_t>(address);
auto addr = reinterpret_cast<uintptr_t>(address);
return addr >= start_ && addr < end_;
}
......
......@@ -156,7 +156,7 @@ void JemallocNodumpAllocator::deallocate(void* p, size_t) {
}
void JemallocNodumpAllocator::deallocate(void* p, void* userData) {
const uint64_t flags = reinterpret_cast<uint64_t>(userData);
const auto flags = reinterpret_cast<uint64_t>(userData);
dallocx != nullptr ? dallocx(p, static_cast<int>(flags)) : free(p);
}
......
......@@ -76,7 +76,7 @@ bool TimerFD::setTimer(std::chrono::microseconds useconds) {
void TimerFD::handlerReady(uint16_t events) noexcept {
DestructorGuard dg(this);
uint16_t relevantEvents = uint16_t(events & folly::EventHandler::READ_WRITE);
auto relevantEvents = uint16_t(events & folly::EventHandler::READ_WRITE);
if (relevantEvents == folly::EventHandler::READ ||
relevantEvents == folly::EventHandler::READ_WRITE) {
uint64_t data = 0;
......
......@@ -63,11 +63,11 @@ void initStateFromParams(
const detail::Blake2xbParam& param,
ByteRange key) {
#ifdef __LIBSODIUM_BLAKE2B_OPAQUE__
_blake2b_state* state = reinterpret_cast<_blake2b_state*>(_state);
auto state = reinterpret_cast<_blake2b_state*>(_state);
#else
crypto_generichash_blake2b_state* state = _state;
#endif
const uint64_t* p = reinterpret_cast<const uint64_t*>(&param);
auto p = reinterpret_cast<const uint64_t*>(&param);
for (int i = 0; i < 8; ++i) {
state->h[i] = kBlake2bIV.data()[i] ^ Endian::little(p[i]);
}
......@@ -169,7 +169,7 @@ void Blake2xb::finish(MutableByteRange out) {
}
if (outputLengthKnown_) {
uint32_t outLength = static_cast<uint32_t>(out.size());
auto outLength = static_cast<uint32_t>(out.size());
if (outLength != Endian::little(param_.xofLength)) {
throw std::runtime_error("out.size() must equal output length");
}
......
......@@ -48,7 +48,7 @@ std::unique_ptr<folly::IOBuf> allocateCacheAlignedIOBufUnique(size_t size) {
}
bool isCacheAlignedAddress(const void* addr) {
size_t addrValue = reinterpret_cast<size_t>(addr);
auto addrValue = reinterpret_cast<size_t>(addr);
return (addrValue & (kCacheLineSize - 1)) == 0;
}
......
......@@ -69,8 +69,8 @@ void MathOperation<MathEngine::SSE2>::add(
// the Endian::little() conversions when loading or storing data.
if (bitsPerElement == 16 || bitsPerElement == 32) {
for (size_t pos = 0; pos < b1.size(); pos += kCacheLineSize) {
const __m128i* v1p = reinterpret_cast<const __m128i*>(b1.data() + pos);
const __m128i* v2p = reinterpret_cast<const __m128i*>(b2.data() + pos);
auto v1p = reinterpret_cast<const __m128i*>(b1.data() + pos);
auto v2p = reinterpret_cast<const __m128i*>(b2.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
__m128i v1 = _mm_load_si128(v1p + i);
__m128i v2 = _mm_load_si128(v2p + i);
......@@ -85,8 +85,8 @@ void MathOperation<MathEngine::SSE2>::add(
} else {
__m128i mask = _mm_set_epi64x(dataMask, dataMask);
for (size_t pos = 0; pos < b1.size(); pos += kCacheLineSize) {
const __m128i* v1p = reinterpret_cast<const __m128i*>(b1.data() + pos);
const __m128i* v2p = reinterpret_cast<const __m128i*>(b2.data() + pos);
auto v1p = reinterpret_cast<const __m128i*>(b1.data() + pos);
auto v2p = reinterpret_cast<const __m128i*>(b2.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
__m128i v1 = _mm_load_si128(v1p + i);
__m128i v2 = _mm_load_si128(v2p + i);
......@@ -125,8 +125,8 @@ void MathOperation<MathEngine::SSE2>::sub(
// the Endian::little() conversions when loading or storing data.
if (bitsPerElement == 16 || bitsPerElement == 32) {
for (size_t pos = 0; pos < b1.size(); pos += kCacheLineSize) {
const __m128i* v1p = reinterpret_cast<const __m128i*>(b1.data() + pos);
const __m128i* v2p = reinterpret_cast<const __m128i*>(b2.data() + pos);
auto v1p = reinterpret_cast<const __m128i*>(b1.data() + pos);
auto v2p = reinterpret_cast<const __m128i*>(b2.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
__m128i v1 = _mm_load_si128(v1p + i);
__m128i v2 = _mm_load_si128(v2p + i);
......@@ -142,8 +142,8 @@ void MathOperation<MathEngine::SSE2>::sub(
__m128i mask = _mm_set_epi64x(dataMask, dataMask);
__m128i paddingMask = _mm_set_epi64x(~dataMask, ~dataMask);
for (size_t pos = 0; pos < b1.size(); pos += kCacheLineSize) {
const __m128i* v1p = reinterpret_cast<const __m128i*>(b1.data() + pos);
const __m128i* v2p = reinterpret_cast<const __m128i*>(b2.data() + pos);
auto v1p = reinterpret_cast<const __m128i*>(b1.data() + pos);
auto v2p = reinterpret_cast<const __m128i*>(b2.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
__m128i v1 = _mm_load_si128(v1p + i);
__m128i v2 = _mm_load_si128(v2p + i);
......@@ -179,7 +179,7 @@ void MathOperation<MathEngine::SSE2>::clearPaddingBits(
__m128i mask = _mm_set_epi64x(dataMask, dataMask);
for (size_t pos = 0; pos < buf.size(); pos += kCacheLineSize) {
const __m128i* p = reinterpret_cast<const __m128i*>(buf.data() + pos);
auto p = reinterpret_cast<const __m128i*>(buf.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
results[i] = _mm_and_si128(_mm_load_si128(p + i), mask);
}
......
......@@ -69,8 +69,8 @@ void MathOperation<MathEngine::SIMPLE>::add(
bitsPerElement == 16 ? 0xffff0000ffff0000ULL : 0xffffffff00000000ULL;
const uint64_t kMaskB = ~kMaskA;
for (size_t pos = 0; pos < b1.size(); pos += kCacheLineSize) {
const uint64_t* v1p = reinterpret_cast<const uint64_t*>(b1.data() + pos);
const uint64_t* v2p = reinterpret_cast<const uint64_t*>(b2.data() + pos);
auto v1p = reinterpret_cast<const uint64_t*>(b1.data() + pos);
auto v2p = reinterpret_cast<const uint64_t*>(b2.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
uint64_t v1 = Endian::little(*(v1p + i));
uint64_t v2 = Endian::little(*(v2p + i));
......@@ -86,8 +86,8 @@ void MathOperation<MathEngine::SIMPLE>::add(
}
} else {
for (size_t pos = 0; pos < b1.size(); pos += kCacheLineSize) {
const uint64_t* v1p = reinterpret_cast<const uint64_t*>(b1.data() + pos);
const uint64_t* v2p = reinterpret_cast<const uint64_t*>(b2.data() + pos);
auto v1p = reinterpret_cast<const uint64_t*>(b1.data() + pos);
auto v2p = reinterpret_cast<const uint64_t*>(b2.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
uint64_t v1 = Endian::little(*(v1p + i));
uint64_t v2 = Endian::little(*(v2p + i));
......@@ -134,8 +134,8 @@ void MathOperation<MathEngine::SIMPLE>::sub(
bitsPerElement == 16 ? 0xffff0000ffff0000ULL : 0xffffffff00000000ULL;
const uint64_t kMaskB = ~kMaskA;
for (size_t pos = 0; pos < b1.size(); pos += kCacheLineSize) {
const uint64_t* v1p = reinterpret_cast<const uint64_t*>(b1.data() + pos);
const uint64_t* v2p = reinterpret_cast<const uint64_t*>(b2.data() + pos);
auto v1p = reinterpret_cast<const uint64_t*>(b1.data() + pos);
auto v2p = reinterpret_cast<const uint64_t*>(b2.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
uint64_t v1 = Endian::little(*(v1p + i));
uint64_t v2 = Endian::little(*(v2p + i));
......@@ -151,8 +151,8 @@ void MathOperation<MathEngine::SIMPLE>::sub(
}
} else {
for (size_t pos = 0; pos < b1.size(); pos += kCacheLineSize) {
const uint64_t* v1p = reinterpret_cast<const uint64_t*>(b1.data() + pos);
const uint64_t* v2p = reinterpret_cast<const uint64_t*>(b2.data() + pos);
auto v1p = reinterpret_cast<const uint64_t*>(b1.data() + pos);
auto v2p = reinterpret_cast<const uint64_t*>(b2.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
uint64_t v1 = Endian::little(*(v1p + i));
uint64_t v2 = Endian::little(*(v2p + i));
......@@ -181,7 +181,7 @@ void MathOperation<MathEngine::SIMPLE>::clearPaddingBits(
kValsPerCacheLine > 0, "kCacheLineSize must be >= sizeof(uint64_t)");
alignas(kCacheLineSize) std::array<uint64_t, kValsPerCacheLine> results;
for (size_t pos = 0; pos < buf.size(); pos += kCacheLineSize) {
const uint64_t* p = reinterpret_cast<const uint64_t*>(buf.data() + pos);
auto p = reinterpret_cast<const uint64_t*>(buf.data() + pos);
for (size_t i = 0; i < kValsPerCacheLine; ++i) {
results[i] = Endian::little(Endian::little(*(p + i)) & dataMask);
}
......
......@@ -38,7 +38,7 @@ namespace {
return #c
const char* iocbCmdToString(short int cmd_short) {
io_iocb_cmd cmd = static_cast<io_iocb_cmd>(cmd_short);
auto cmd = static_cast<io_iocb_cmd>(cmd_short);
switch (cmd) {
X(IO_CMD_PREAD);
X(IO_CMD_PWRITE);
......
......@@ -159,7 +159,7 @@ HugePageSizeVec readHugePageSizes() {
// Search for the "pagesize" option, which must have a value
for (auto& option : options) {
// key=value
const char* p = static_cast<const char*>(
auto p = static_cast<const char*>(
memchr(option.data(), '=', option.size()));
if (!p) {
continue;
......
......@@ -41,8 +41,8 @@ std::thread::id localThreadId() {
static size_t nonMagicInBytes(unsigned char* stackLimit, size_t stackSize) {
CHECK_EQ(reinterpret_cast<intptr_t>(stackLimit) % sizeof(uint64_t), 0u);
CHECK_EQ(stackSize % sizeof(uint64_t), 0u);
uint64_t* begin = reinterpret_cast<uint64_t*>(stackLimit);
uint64_t* end = reinterpret_cast<uint64_t*>(stackLimit + stackSize);
auto begin = reinterpret_cast<uint64_t*>(stackLimit);
auto end = reinterpret_cast<uint64_t*>(stackLimit + stackSize);
auto firstNonMagic = std::find_if(
begin, end, [](uint64_t val) { return val != kMagic8Bytes; });
......
......@@ -171,7 +171,7 @@ class StackCache {
std::vector<std::pair<unsigned char*, bool>> freeList_;
static size_t pagesize() {
static const size_t pagesize = size_t(sysconf(_SC_PAGESIZE));
static const auto pagesize = size_t(sysconf(_SC_PAGESIZE));
return pagesize;
}
......
......@@ -348,7 +348,7 @@ void SpookyHashV1::Final(uint64_t *hash1, uint64_t *hash2)
return;
}
const uint64_t *data = (const uint64_t *)m_data;
auto data = (const uint64_t *)m_data;
uint8_t remainder = m_remainder;
uint64_t h0 = m_state[0];
......
......@@ -136,9 +136,9 @@ void IOBuf::SharedInfo::invokeAndDeleteEachObserver(
if (observerListHead && cb) {
// break the chain
observerListHead->prev->next = nullptr;
auto* entry = observerListHead;
auto entry = observerListHead;
while (entry) {
auto* tmp = entry->next;
auto tmp = entry->next;
cb(*entry);
delete entry;
entry = tmp;
......@@ -148,9 +148,9 @@ void IOBuf::SharedInfo::invokeAndDeleteEachObserver(
void IOBuf::SharedInfo::releaseStorage(SharedInfo* info) noexcept {
if (info->useHeapFullStorage) {
auto* storageAddr =
auto storageAddr =
reinterpret_cast<uint8_t*>(info) - offsetof(HeapFullStorage, shared);
auto* storage = reinterpret_cast<HeapFullStorage*>(storageAddr);
auto storage = reinterpret_cast<HeapFullStorage*>(storageAddr);
info->~SharedInfo();
IOBuf::releaseStorage(&storage->hs, kSharedInfoInUse);
}
......@@ -158,7 +158,7 @@ void IOBuf::SharedInfo::releaseStorage(SharedInfo* info) noexcept {
void* IOBuf::operator new(size_t size) {
size_t fullSize = offsetof(HeapStorage, buf) + size;
auto* storage = static_cast<HeapStorage*>(checkedMalloc(fullSize));
auto storage = static_cast<HeapStorage*>(checkedMalloc(fullSize));
new (&storage->prefix) HeapPrefix(kIOBufInUse);
return &(storage->buf);
......@@ -169,8 +169,8 @@ void* IOBuf::operator new(size_t /* size */, void* ptr) {
}
void IOBuf::operator delete(void* ptr) {
auto* storageAddr = static_cast<uint8_t*>(ptr) - offsetof(HeapStorage, buf);
auto* storage = reinterpret_cast<HeapStorage*>(storageAddr);
auto storageAddr = static_cast<uint8_t*>(ptr) - offsetof(HeapStorage, buf);
auto storage = reinterpret_cast<HeapStorage*>(storageAddr);
releaseStorage(storage, kIOBufInUse);
}
......@@ -190,7 +190,7 @@ void IOBuf::releaseStorage(HeapStorage* storage, uint16_t freeFlags) noexcept {
DCHECK_EQ((flags & freeFlags), freeFlags);
while (true) {
uint16_t newFlags = uint16_t(flags & ~freeFlags);
auto newFlags = uint16_t(flags & ~freeFlags);
if (newFlags == 0) {
// The storage space is now unused. Free it.
storage->prefix.HeapPrefix::~HeapPrefix();
......@@ -214,7 +214,7 @@ void IOBuf::releaseStorage(HeapStorage* storage, uint16_t freeFlags) noexcept {
}
void IOBuf::freeInternalBuf(void* /* buf */, void* userData) noexcept {
auto* storage = static_cast<HeapStorage*>(userData);
auto storage = static_cast<HeapStorage*>(userData);
releaseStorage(storage, kDataInUse);
}
......@@ -273,14 +273,14 @@ unique_ptr<IOBuf> IOBuf::createCombined(std::size_t capacity) {
// SharedInfo struct, and the data itself all with a single call to malloc().
size_t requiredStorage = offsetof(HeapFullStorage, align) + capacity;
size_t mallocSize = goodMallocSize(requiredStorage);
auto* storage = static_cast<HeapFullStorage*>(checkedMalloc(mallocSize));
auto storage = static_cast<HeapFullStorage*>(checkedMalloc(mallocSize));
new (&storage->hs.prefix) HeapPrefix(kIOBufInUse | kDataInUse);
new (&storage->shared) SharedInfo(freeInternalBuf, storage);
uint8_t* bufAddr = reinterpret_cast<uint8_t*>(&storage->align);
auto bufAddr = reinterpret_cast<uint8_t*>(&storage->align);
uint8_t* storageEnd = reinterpret_cast<uint8_t*>(storage) + mallocSize;
size_t actualCapacity = size_t(storageEnd - bufAddr);
auto actualCapacity = size_t(storageEnd - bufAddr);
unique_ptr<IOBuf> ret(new (&storage->hs.buf) IOBuf(
InternalConstructor(),
packFlagsAndSharedInfo(0, &storage->shared),
......@@ -968,7 +968,7 @@ void IOBuf::freeExtBuffer() noexcept {
// save the observerListHead
// since the SharedInfo can be freed
auto* observerListHead = info->observerListHead;
auto observerListHead = info->observerListHead;
info->observerListHead = nullptr;
if (info->freeFn) {
......@@ -987,7 +987,7 @@ void IOBuf::allocExtBuffer(
SharedInfo** infoReturn,
std::size_t* capacityReturn) {
size_t mallocSize = goodExtBufferSize(minCapacity);
uint8_t* buf = static_cast<uint8_t*>(checkedMalloc(mallocSize));
auto buf = static_cast<uint8_t*>(checkedMalloc(mallocSize));
initExtBuffer(buf, mallocSize, infoReturn, capacityReturn);
*bufReturn = buf;
}
......@@ -1016,7 +1016,7 @@ void IOBuf::initExtBuffer(
// Find the SharedInfo storage at the end of the buffer
// and construct the SharedInfo.
uint8_t* infoStart = (buf + mallocSize) - sizeof(SharedInfo);
SharedInfo* sharedInfo = new (infoStart) SharedInfo;
auto sharedInfo = new (infoStart) SharedInfo;
*capacityReturn = std::size_t(infoStart - buf);
*infoReturn = sharedInfo;
......@@ -1039,7 +1039,7 @@ fbstring IOBuf::moveToFbString() {
// to reallocate; we need 1 byte for NUL terminator.
coalesceAndReallocate(0, computeChainDataLength(), this, 1);
} else {
auto* info = sharedInfo();
auto info = sharedInfo();
if (info) {
// if we do not call coalesceAndReallocate
// we might need to call SharedInfo::releaseStorage()
......
......@@ -91,7 +91,7 @@ void RecordIOReader::Iterator::advanceToValid() {
recordAndPos_ = std::make_pair(ByteRange(), off_t(-1));
range_.clear(); // at end
} else {
size_t skipped = size_t(record.begin() - range_.begin());
auto skipped = size_t(record.begin() - range_.begin());
DCHECK_GE(skipped, headerSize());
skipped -= headerSize();
range_.advance(skipped);
......@@ -156,7 +156,7 @@ size_t prependHeader(std::unique_ptr<IOBuf>& buf, uint32_t fileId) {
b->appendChain(std::move(buf));
buf = std::move(b);
}
Header* header = reinterpret_cast<Header*>(buf->writableData());
auto header = reinterpret_cast<Header*>(buf->writableData());
memset(header, 0, sizeof(Header));
header->magic = Header::kMagic;
header->fileId = fileId;
......@@ -171,7 +171,7 @@ bool validateRecordHeader(ByteRange range, uint32_t fileId) {
if (range.size() < headerSize()) { // records may not be empty
return false;
}
const Header* header = reinterpret_cast<const Header*>(range.begin());
auto header = reinterpret_cast<const Header*>(range.begin());
if (header->magic != Header::kMagic || header->version != 0 ||
header->hashFunction != 0 || header->flags != 0 ||
(fileId != 0 && header->fileId != fileId)) {
......@@ -187,7 +187,7 @@ RecordInfo validateRecordData(ByteRange range) {
if (range.size() <= headerSize()) { // records may not be empty
return {0, {}};
}
const Header* header = reinterpret_cast<const Header*>(range.begin());
auto header = reinterpret_cast<const Header*>(range.begin());
range.advance(sizeof(Header));
if (header->dataLength > range.size()) {
return {0, {}};
......
......@@ -1812,7 +1812,7 @@ void AsyncSSLSocket::clientHelloParsingCallback(
size_t len,
SSL* ssl,
void* arg) {
AsyncSSLSocket* sock = static_cast<AsyncSSLSocket*>(arg);
auto sock = static_cast<AsyncSSLSocket*>(arg);
if (written != 0) {
sock->resetClientHelloParsing(ssl);
return;
......@@ -1858,26 +1858,26 @@ void AsyncSSLSocket::clientHelloParsingCallback(
cursor.skip(cursor.read<uint8_t>()); // session_id
uint16_t cipherSuitesLength = cursor.readBE<uint16_t>();
auto cipherSuitesLength = cursor.readBE<uint16_t>();
for (int i = 0; i < cipherSuitesLength; i += 2) {
sock->clientHelloInfo_->clientHelloCipherSuites_.push_back(
cursor.readBE<uint16_t>());
}
uint8_t compressionMethodsLength = cursor.read<uint8_t>();
auto compressionMethodsLength = cursor.read<uint8_t>();
for (int i = 0; i < compressionMethodsLength; ++i) {
sock->clientHelloInfo_->clientHelloCompressionMethods_.push_back(
cursor.readBE<uint8_t>());
}
if (cursor.totalLength() > 0) {
uint16_t extensionsLength = cursor.readBE<uint16_t>();
auto extensionsLength = cursor.readBE<uint16_t>();
while (extensionsLength) {
ssl::TLSExtension extensionType =
auto extensionType =
static_cast<ssl::TLSExtension>(cursor.readBE<uint16_t>());
sock->clientHelloInfo_->clientHelloExtensions_.push_back(extensionType);
extensionsLength -= 2;
uint16_t extensionDataLength = cursor.readBE<uint16_t>();
auto extensionDataLength = cursor.readBE<uint16_t>();
extensionsLength -= 2;
extensionsLength -= extensionDataLength;
......@@ -1885,9 +1885,9 @@ void AsyncSSLSocket::clientHelloParsingCallback(
cursor.skip(2);
extensionDataLength -= 2;
while (extensionDataLength) {
ssl::HashAlgorithm hashAlg =
auto hashAlg =
static_cast<ssl::HashAlgorithm>(cursor.readBE<uint8_t>());
ssl::SignatureAlgorithm sigAlg =
auto sigAlg =
static_cast<ssl::SignatureAlgorithm>(cursor.readBE<uint8_t>());
extensionDataLength -= 2;
sock->clientHelloInfo_->clientHelloSigAlgs_.emplace_back(
......@@ -1911,9 +1911,9 @@ void AsyncSSLSocket::clientHelloParsingCallback(
uint8_t>::value,
"unexpected underlying type");
ssl::NameType typ =
auto typ =
static_cast<ssl::NameType>(cursor.readBE<uint8_t>());
uint16_t nameLength = cursor.readBE<uint16_t>();
auto nameLength = cursor.readBE<uint16_t>();
if (typ == NameType::HOST_NAME &&
sock->clientHelloInfo_->clientHelloSNIHostname_.empty() &&
......
......@@ -212,7 +212,7 @@ int AsyncServerSocket::stopAccepting(int shutdownFlags) {
// removeAcceptCallback().
std::vector<CallbackInfo> callbacksCopy;
callbacks_.swap(callbacksCopy);
for (std::vector<CallbackInfo>::iterator it = callbacksCopy.begin();
for (auto it = callbacksCopy.begin();
it != callbacksCopy.end();
++it) {
// consumer may not be set if we are running in primary event base
......@@ -302,7 +302,7 @@ void AsyncServerSocket::bindSocket(
bool isExistingSocket) {
sockaddr_storage addrStorage;
address.getAddress(&addrStorage);
sockaddr* saddr = reinterpret_cast<sockaddr*>(&addrStorage);
auto saddr = reinterpret_cast<sockaddr*>(&addrStorage);
if (netops::bind(fd, saddr, address.getActualSize()) != 0) {
if (errno != EINPROGRESS) {
......@@ -616,7 +616,7 @@ void AsyncServerSocket::removeAcceptCallback(
// We just do a simple linear search; we don't expect removeAcceptCallback()
// to be called frequently, and we expect there to only be a small number of
// callbacks anyway.
std::vector<CallbackInfo>::iterator it = callbacks_.begin();
auto it = callbacks_.begin();
uint32_t n = 0;
while (true) {
if (it == callbacks_.end()) {
......@@ -841,7 +841,7 @@ void AsyncServerSocket::handlerReady(
sockaddr_storage addrStorage = {};
socklen_t addrLen = sizeof(addrStorage);
sockaddr* saddr = reinterpret_cast<sockaddr*>(&addrStorage);
auto saddr = reinterpret_cast<sockaddr*>(&addrStorage);
// In some cases, accept() doesn't seem to update these correctly.
saddr->sa_family = addressFamily;
......
......@@ -31,7 +31,7 @@ AsyncSignalHandler::AsyncSignalHandler(EventBase* eventBase)
AsyncSignalHandler::~AsyncSignalHandler() {
// Unregister any outstanding events
for (SignalEventMap::iterator it = signalEvents_.begin();
for (auto it = signalEvents_.begin();
it != signalEvents_.end();
++it) {
event_del(&it->second);
......@@ -78,7 +78,7 @@ void AsyncSignalHandler::registerSignalHandler(int signum) {
}
void AsyncSignalHandler::unregisterSignalHandler(int signum) {
SignalEventMap::iterator it = signalEvents_.find(signum);
auto it = signalEvents_.find(signum);
if (it == signalEvents_.end()) {
throw std::runtime_error(folly::to<string>(
"unable to unregister handler for signal ",
......@@ -94,7 +94,7 @@ void AsyncSignalHandler::libeventCallback(
libevent_fd_t signum,
short /* events */,
void* arg) {
AsyncSignalHandler* handler = static_cast<AsyncSignalHandler*>(arg);
auto handler = static_cast<AsyncSignalHandler*>(arg);
handler->signalReceived(int(signum));
}
......
......@@ -468,7 +468,7 @@ void AsyncSocket::connect(
connectCallback_ = callback;
sockaddr_storage addrStorage;
sockaddr* saddr = reinterpret_cast<sockaddr*>(&addrStorage);
auto saddr = reinterpret_cast<sockaddr*>(&addrStorage);
try {
// Create the socket
......@@ -981,7 +981,7 @@ bool AsyncSocket::isZeroCopyMsg(const cmsghdr& cmsg) const {
#ifdef FOLLY_HAVE_MSG_ERRQUEUE
if ((cmsg.cmsg_level == SOL_IP && cmsg.cmsg_type == IP_RECVERR) ||
(cmsg.cmsg_level == SOL_IPV6 && cmsg.cmsg_type == IPV6_RECVERR)) {
const struct sock_extended_err* serr =
auto serr =
reinterpret_cast<const struct sock_extended_err*>(CMSG_DATA(&cmsg));
return (
(serr->ee_errno == 0) && (serr->ee_origin == SO_EE_ORIGIN_ZEROCOPY));
......@@ -993,7 +993,7 @@ bool AsyncSocket::isZeroCopyMsg(const cmsghdr& cmsg) const {
void AsyncSocket::processZeroCopyMsg(const cmsghdr& cmsg) {
#ifdef FOLLY_HAVE_MSG_ERRQUEUE
const struct sock_extended_err* serr =
auto serr =
reinterpret_cast<const struct sock_extended_err*>(CMSG_DATA(&cmsg));
uint32_t hi = serr->ee_data;
uint32_t lo = serr->ee_info;
......@@ -1791,7 +1791,7 @@ void AsyncSocket::ioReady(uint16_t events) noexcept {
assert(events & EventHandler::READ_WRITE);
eventBase_->dcheckIsInEventBaseThread();
uint16_t relevantEvents = uint16_t(events & EventHandler::READ_WRITE);
auto relevantEvents = uint16_t(events & EventHandler::READ_WRITE);
EventBase* originalEventBase = eventBase_;
// If we got there it means that either EventHandler::READ or
// EventHandler::WRITE is set. Any of these flags can
......
......@@ -156,7 +156,7 @@ void AsyncTimeout::detachEventBase() {
}
void AsyncTimeout::libeventCallback(libevent_fd_t fd, short events, void* arg) {
AsyncTimeout* timeout = reinterpret_cast<AsyncTimeout*>(arg);
auto timeout = reinterpret_cast<AsyncTimeout*>(arg);
assert(fd == NetworkSocket::invalid_handle_value);
assert(events == EV_TIMEOUT);
// prevent unused variable warnings
......
......@@ -331,7 +331,7 @@ ssize_t AsyncUDPSocket::writev(
cm->cmsg_level = SOL_UDP;
cm->cmsg_type = UDP_SEGMENT;
cm->cmsg_len = CMSG_LEN(sizeof(uint16_t));
uint16_t gso_len = static_cast<uint16_t>(gso);
auto gso_len = static_cast<uint16_t>(gso);
memcpy(CMSG_DATA(cm), &gso_len, sizeof(gso_len));
return sendmsg(fd_, &msg, 0);
......@@ -608,7 +608,7 @@ void AsyncUDPSocket::handleRead() noexcept {
struct sockaddr_storage addrStorage;
socklen_t addrLen = sizeof(addrStorage);
memset(&addrStorage, 0, size_t(addrLen));
struct sockaddr* rawAddr = reinterpret_cast<sockaddr*>(&addrStorage);
auto rawAddr = reinterpret_cast<sockaddr*>(&addrStorage);
rawAddr->sa_family = localAddress_.getFamily();
ssize_t bytesRead =
......
......@@ -26,7 +26,7 @@ EventBaseManager* EventBaseManager::get() {
return mgr;
}
EventBaseManager* new_mgr = new EventBaseManager;
auto new_mgr = new EventBaseManager;
bool exchanged = globalManager.compare_exchange_strong(mgr, new_mgr);
if (!exchanged) {
delete new_mgr;
......
......@@ -146,7 +146,7 @@ void EventHandler::ensureNotRegistered(const char* fn) {
}
void EventHandler::libeventCallback(libevent_fd_t fd, short events, void* arg) {
EventHandler* handler = reinterpret_cast<EventHandler*>(arg);
auto handler = reinterpret_cast<EventHandler*>(arg);
assert(fd == handler->event_.ev_fd);
(void)fd; // prevent unused variable warnings
......
......@@ -392,7 +392,7 @@ void SSLContext::addClientHelloCallback(const ClientHelloCallback& cb) {
}
int SSLContext::baseServerNameOpenSSLCallback(SSL* ssl, int* al, void* data) {
SSLContext* context = (SSLContext*)data;
auto context = (SSLContext*)data;
if (context == nullptr) {
return SSL_TLSEXT_ERR_NOACK;
......@@ -437,7 +437,7 @@ int SSLContext::alpnSelectCallback(
const unsigned char* in,
unsigned int inlen,
void* data) {
SSLContext* context = (SSLContext*)data;
auto context = (SSLContext*)data;
CHECK(context);
if (context->advertisedNextProtocols_.empty()) {
*out = nullptr;
......@@ -491,7 +491,7 @@ bool SSLContext::setRandomizedAdvertisedNextProtocols(
}
unsigned char* dst = advertised_item.protocols;
for (auto& proto : item.protocols) {
uint8_t protoLength = uint8_t(proto.length());
auto protoLength = uint8_t(proto.length());
*dst++ = (unsigned char)protoLength;
memcpy(dst, proto.data(), protoLength);
dst += protoLength;
......@@ -595,7 +595,7 @@ bool SSLContext::matchName(const char* host, const char* pattern, int size) {
}
int SSLContext::passwordCallback(char* password, int size, int, void* data) {
SSLContext* context = (SSLContext*)data;
auto context = (SSLContext*)data;
if (context == nullptr || context->passwordCollector() == nullptr) {
return 0;
}
......
......@@ -129,7 +129,7 @@ bool OpenSSLUtils::validatePeerCertNames(
if ((addr4 != nullptr || addr6 != nullptr) && name->type == GEN_IPADD) {
// Extra const-ness for paranoia
unsigned char const* const rawIpStr = name->d.iPAddress->data;
size_t const rawIpLen = size_t(name->d.iPAddress->length);
auto const rawIpLen = size_t(name->d.iPAddress->length);
if (rawIpLen == 4 && addr4 != nullptr) {
if (::memcmp(rawIpStr, &addr4->sin_addr, rawIpLen) == 0) {
......
......@@ -187,7 +187,7 @@ static nanoseconds getSchedTimeWaiting(pid_t tid) {
throw std::runtime_error(
folly::to<string>("failed to read process schedstat file", errno));
}
size_t bytesRead = size_t(bytesReadRet);
auto bytesRead = size_t(bytesReadRet);
if (buf[bytesRead - 1] != '\n') {
throw std::runtime_error("expected newline at end of schedstat data");
......
......@@ -546,7 +546,7 @@ std::string decodeUnicodeEscape(Input& in) {
in.error("expected 4 hex digits");
}
uint16_t ret = uint16_t(hexVal(*in) * 4096);
auto ret = uint16_t(hexVal(*in) * 4096);
++in;
ret += hexVal(*in) * 256;
++in;
......
......@@ -24,7 +24,7 @@ ThreadCachedArena::ThreadCachedArena(size_t minBlockSize, size_t maxAlign)
: minBlockSize_(minBlockSize), maxAlign_(maxAlign) {}
SysArena* ThreadCachedArena::allocateThreadLocalArena() {
SysArena* arena =
auto arena =
new SysArena(minBlockSize_, SysArena::kNoSizeLimit, maxAlign_);
auto disposer = [this](SysArena* t, TLPDestructionMode mode) {
std::unique_ptr<SysArena> tp(t); // ensure it gets deleted
......
......@@ -169,7 +169,7 @@ int poll(PollDescriptor fds[], nfds_t nfds, int timeout) {
"PollDescriptor.revents is the wrong size");
// Pun it through
pollfd* files = reinterpret_cast<pollfd*>(reinterpret_cast<void*>(fds));
auto files = reinterpret_cast<pollfd*>(reinterpret_cast<void*>(fds));
#ifdef _WIN32
return ::WSAPoll(files, (ULONG)nfds, timeout);
#else
......
......@@ -261,7 +261,7 @@ TDigest TDigest::merge(Range<const TDigest*> digests) {
// It is possible that the next block is incomplete (less than
// digestsPerBlock big). In that case, merge to end. Otherwise, merge to
// the end of that block.
std::vector<Centroid>::iterator last =
auto last =
(i + (digestsPerBlock * 2) < starts.size())
? *(starts.begin() + i + 2 * digestsPerBlock)
: centroids.end();
......
......@@ -212,7 +212,7 @@ void MemoryMapping::init(off_t offset, off_t length) {
(options_.writable ? PROT_WRITE : 0));
}
unsigned char* start = static_cast<unsigned char*>(mmap(
auto start = static_cast<unsigned char*>(mmap(
options_.address, size_t(mapLength_), prot, flags, file_.fd(), offset));
PCHECK(start != MAP_FAILED)
<< " offset=" << offset << " length=" << mapLength_;
......@@ -257,9 +257,9 @@ bool memOpInChunks(
// chunks breaks the locking into intervals and lets other threads do memory
// operations of their own.
size_t chunkSize = size_t(memOpChunkSize(off_t(bufSize), pageSize));
auto chunkSize = size_t(memOpChunkSize(off_t(bufSize), pageSize));
char* addr = static_cast<char*>(mem);
auto addr = static_cast<char*>(mem);
amountSucceeded = 0;
while (amountSucceeded < bufSize) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment