diff --git a/folly/io/IOBuf.cpp b/folly/io/IOBuf.cpp index 214abbaab0e..4eba7aca154 100644 --- a/folly/io/IOBuf.cpp +++ b/folly/io/IOBuf.cpp @@ -670,7 +670,7 @@ IOBuf& IOBuf::operator=(const IOBuf& other) { return *this; } -bool IOBuf::empty() const { +bool IOBuf::empty() const noexcept { const IOBuf* current = this; do { if (current->length() != 0) { @@ -681,7 +681,7 @@ bool IOBuf::empty() const { return true; } -size_t IOBuf::countChainElements() const { +size_t IOBuf::countChainElements() const noexcept { size_t numElements = 1; for (IOBuf* current = next_; current != this; current = current->next_) { ++numElements; @@ -689,7 +689,7 @@ size_t IOBuf::countChainElements() const { return numElements; } -std::size_t IOBuf::computeChainDataLength() const { +std::size_t IOBuf::computeChainDataLength() const noexcept { std::size_t fullLength = length_; for (IOBuf* current = next_; current != this; current = current->next_) { fullLength += current->length_; @@ -697,7 +697,7 @@ std::size_t IOBuf::computeChainDataLength() const { return fullLength; } -std::size_t IOBuf::computeChainCapacity() const { +std::size_t IOBuf::computeChainCapacity() const noexcept { std::size_t fullCapacity = capacity_; for (IOBuf* current = next_; current != this; current = current->next_) { fullCapacity += current->capacity_; @@ -1411,7 +1411,7 @@ IOBuf::FillIovResult IOBuf::fillIov(struct iovec* iov, size_t len) const { return {0, 0}; } -uint32_t IOBuf::approximateShareCountOne() const { +uint32_t IOBuf::approximateShareCountOne() const noexcept { if (FOLLY_UNLIKELY(!sharedInfo_)) { return 1U; } diff --git a/folly/io/IOBuf.h b/folly/io/IOBuf.h index 447d02eb472..8bcc253d144 100644 --- a/folly/io/IOBuf.h +++ b/folly/io/IOBuf.h @@ -776,14 +776,14 @@ class IOBuf { * * @methodset Chaining */ - bool empty() const; + bool empty() const noexcept; /** * Get the pointer to the start of the data. * * @methodset Access */ - const uint8_t* data() const { return data_; } + const uint8_t* data() const noexcept { return data_; } /** * Get a writable pointer to the start of the data. @@ -793,14 +793,14 @@ class IOBuf { * * @methodset Access */ - uint8_t* writableData() { return data_; } + uint8_t* writableData() noexcept { return data_; } /** * Get the pointer to the end of the data. * * @methodset Access */ - const uint8_t* tail() const { return data_ + length_; } + const uint8_t* tail() const noexcept { return data_ + length_; } /** * Get a writable pointer to the end of the data. @@ -810,7 +810,7 @@ class IOBuf { * * @methodset Access */ - uint8_t* writableTail() { return data_ + length_; } + uint8_t* writableTail() noexcept { return data_ + length_; } /** * Get the size of the data for this individual IOBuf in the chain. @@ -819,7 +819,7 @@ class IOBuf { * * @methodset Buffer Capacity */ - std::size_t length() const { return length_; } + std::size_t length() const noexcept { return length_; } /** * Get the amount of head room. @@ -828,7 +828,9 @@ class IOBuf { * * @methodset Buffer Capacity */ - std::size_t headroom() const { return std::size_t(data_ - buffer()); } + std::size_t headroom() const noexcept { + return std::size_t(data_ - buffer()); + } /** * Get the amount of tail room. @@ -837,7 +839,9 @@ class IOBuf { * * @methodset Buffer Capacity */ - std::size_t tailroom() const { return std::size_t(bufferEnd() - tail()); } + std::size_t tailroom() const noexcept { + return std::size_t(bufferEnd() - tail()); + } /** * Get the pointer to the start of the buffer. @@ -848,7 +852,7 @@ class IOBuf { * * @methodset Access */ - const uint8_t* buffer() const { return buf_; } + const uint8_t* buffer() const noexcept { return buf_; } /** * Get a writable pointer to the start of the buffer. @@ -858,7 +862,7 @@ class IOBuf { * * @methodset Access */ - uint8_t* writableBuffer() { return buf_; } + uint8_t* writableBuffer() noexcept { return buf_; } /** * Get the pointer to the end of the buffer. @@ -869,7 +873,7 @@ class IOBuf { * * @methodset Access */ - const uint8_t* bufferEnd() const { return buf_ + capacity_; } + const uint8_t* bufferEnd() const noexcept { return buf_ + capacity_; } /** * Get the total size of the buffer. @@ -879,25 +883,25 @@ class IOBuf { * * @methodset Buffer Capacity */ - std::size_t capacity() const { return capacity_; } + std::size_t capacity() const noexcept { return capacity_; } /** * Get a pointer to the next IOBuf in this chain. * * @methodset Chaining */ - IOBuf* next() { return next_; } + IOBuf* next() noexcept { return next_; } /// @copydoc next() - const IOBuf* next() const { return next_; } + const IOBuf* next() const noexcept { return next_; } /** * Get a pointer to the previous IOBuf in this chain. * * @methodset Chaining */ - IOBuf* prev() { return prev_; } + IOBuf* prev() noexcept { return prev_; } /// @copydoc prev - const IOBuf* prev() const { return prev_; } + const IOBuf* prev() const noexcept { return prev_; } /** * Shift the data forwards in the buffer. @@ -919,7 +923,7 @@ class IOBuf { * * @methodset Shifting */ - void advance(std::size_t amount) { + void advance(std::size_t amount) noexcept { // In debug builds, assert if there is a problem. assert(amount <= tailroom()); @@ -948,7 +952,7 @@ class IOBuf { * * @methodset Shifting */ - void retreat(std::size_t amount) { + void retreat(std::size_t amount) noexcept { // In debug builds, assert if there is a problem. assert(amount <= headroom()); @@ -973,7 +977,7 @@ class IOBuf { * * @methodset Shifting */ - void prepend(std::size_t amount) { + void prepend(std::size_t amount) noexcept { DCHECK_LE(amount, headroom()); data_ -= amount; length_ += amount; @@ -994,7 +998,7 @@ class IOBuf { * * @methodset Shifting */ - void append(std::size_t amount) { + void append(std::size_t amount) noexcept { DCHECK_LE(amount, tailroom()); length_ += amount; } @@ -1013,7 +1017,7 @@ class IOBuf { * * @methodset Shifting */ - void trimStart(std::size_t amount) { + void trimStart(std::size_t amount) noexcept { DCHECK_LE(amount, length_); data_ += amount; length_ -= amount; @@ -1033,7 +1037,7 @@ class IOBuf { * * @methodset Shifting */ - void trimEnd(std::size_t amount) { + void trimEnd(std::size_t amount) noexcept { DCHECK_LE(amount, length_); length_ -= amount; } @@ -1049,7 +1053,7 @@ class IOBuf { * * @methodset Shifting */ - void trimWritableTail(std::size_t amount) { + void trimWritableTail(std::size_t amount) noexcept { DCHECK_LE(amount, tailroom()); capacity_ -= amount; } @@ -1060,7 +1064,7 @@ class IOBuf { * @post data() == buffer() * @post length() == 0 */ - void clear() { + void clear() noexcept { data_ = writableBuffer(); length_ = 0; } @@ -1109,7 +1113,7 @@ class IOBuf { * * @methodset Chaining */ - bool isChained() const { + bool isChained() const noexcept { assert((next_ == this) == (prev_ == this)); return next_ != this; } @@ -1123,7 +1127,7 @@ class IOBuf { * * @methodset Chaining */ - size_t countChainElements() const; + size_t countChainElements() const noexcept; /** * Get the length of all the data in this IOBuf chain. @@ -1132,7 +1136,7 @@ class IOBuf { * * @methodset Chaining */ - std::size_t computeChainDataLength() const; + std::size_t computeChainDataLength() const noexcept; /** * Get the capacity all IOBufs in the chain. @@ -1141,7 +1145,7 @@ class IOBuf { * * @methodset Chaining */ - std::size_t computeChainCapacity() const; + std::size_t computeChainCapacity() const noexcept; /** * Append another IOBuf chain to the end of this chain. @@ -1302,7 +1306,7 @@ class IOBuf { * * @methodset Buffer Management */ - bool isShared() const { + bool isShared() const noexcept { const IOBuf* current = this; while (true) { if (current->isSharedOne()) { @@ -1385,7 +1389,7 @@ class IOBuf { * * @methodset Buffer Management */ - bool isManaged() const { + bool isManaged() const noexcept { const IOBuf* current = this; while (true) { if (!current->isManagedOne()) { @@ -1429,7 +1433,7 @@ class IOBuf { * * @methodset Buffer Management */ - uint32_t approximateShareCountOne() const; + uint32_t approximateShareCountOne() const noexcept; /** * Check if the buffer is shared. diff --git a/folly/io/IOBufQueue.cpp b/folly/io/IOBufQueue.cpp index 004a7569775..13346847c88 100644 --- a/folly/io/IOBufQueue.cpp +++ b/folly/io/IOBufQueue.cpp @@ -94,7 +94,7 @@ IOBufQueue::IOBufQueue(IOBufQueue&& other) noexcept localCache_.attached = true; } -IOBufQueue& IOBufQueue::operator=(IOBufQueue&& other) { +IOBufQueue& IOBufQueue::operator=(IOBufQueue&& other) noexcept { if (&other != this) { other.clearWritableRangeCache(); clearWritableRangeCache(); diff --git a/folly/io/IOBufQueue.h b/folly/io/IOBufQueue.h index d7d53f6f78c..208ff63e1e8 100644 --- a/folly/io/IOBufQueue.h +++ b/folly/io/IOBufQueue.h @@ -66,23 +66,19 @@ class IOBufQueue { } struct WritableRangeCacheData { - std::pair cachedRange; - bool attached{false}; + std::pair cachedRange{}; + bool attached{}; WritableRangeCacheData() = default; - WritableRangeCacheData(WritableRangeCacheData&& other) + WritableRangeCacheData(WritableRangeCacheData&& other) noexcept : cachedRange(other.cachedRange), attached(other.attached) { - other.cachedRange = {nullptr, nullptr}; - other.attached = false; + other.cachedRange = {}; + other.attached = {}; } - WritableRangeCacheData& operator=(WritableRangeCacheData&& other) { - cachedRange = other.cachedRange; - attached = other.attached; - - other.cachedRange = {nullptr, nullptr}; - other.attached = false; - + WritableRangeCacheData& operator=(WritableRangeCacheData&& other) noexcept { + cachedRange = std::exchange(other.cachedRange, {}); + attached = std::exchange(other.attached, {}); return *this; } @@ -133,7 +129,7 @@ class IOBufQueue { * Move constructor/assignment can move the cached range, but must update * the reference in IOBufQueue. */ - WritableRangeCache(WritableRangeCache&& other) + WritableRangeCache(WritableRangeCache&& other) noexcept : data_(std::move(other.data_)), queue_(other.queue_) { if (data_.attached) { queue_->updateCacheRef(data_); @@ -218,7 +214,7 @@ class IOBufQueue { /** * Mark n bytes as occupied (e.g. postallocate). */ - void append(size_t n) { + void append(size_t n) noexcept { dcheckIntegrity(); // This can happen only if somebody is misusing the interface. // E.g. calling append after touching IOBufQueue or without checking @@ -426,7 +422,7 @@ class IOBufQueue { * invoke any other non-const methods on this IOBufQueue between * the call to preallocate and the call to postallocate(). */ - void postallocate(std::size_t n) { + void postallocate(std::size_t n) noexcept { dcheckCacheIntegrity(); DCHECK_LE( (void*)(cachePtr_->cachedRange.first + n), @@ -632,7 +628,7 @@ class IOBufQueue { /** Movable */ IOBufQueue(IOBufQueue&&) noexcept; - IOBufQueue& operator=(IOBufQueue&&); + IOBufQueue& operator=(IOBufQueue&&) noexcept; static constexpr size_t kMaxPackCopy = 4096; @@ -661,7 +657,7 @@ class IOBufQueue { WritableRangeCacheData* cachePtr_{nullptr}; WritableRangeCacheData localCache_; - void dcheckCacheIntegrity() const { + void dcheckCacheIntegrity() const noexcept { // Tail start should always be less than tail end. DCHECK_LE((void*)tailStart_, (void*)cachePtr_->cachedRange.first); DCHECK_LE( @@ -689,7 +685,7 @@ class IOBufQueue { /** * Populate dest with writable tail range cache. */ - void fillWritableRangeCache(WritableRangeCacheData& dest) { + void fillWritableRangeCache(WritableRangeCacheData& dest) noexcept { dcheckCacheIntegrity(); if (cachePtr_ != &dest) { dest = std::move(*cachePtr_); @@ -700,7 +696,7 @@ class IOBufQueue { /** * Clear current writable tail cache and reset it to localCache_ */ - void clearWritableRangeCache() { + void clearWritableRangeCache() noexcept { flushCache(); if (cachePtr_ != &localCache_) { @@ -714,7 +710,7 @@ class IOBufQueue { /** * Commit any pending changes to the tail of the queue. */ - void flushCache() const { + void flushCache() const noexcept { dcheckCacheIntegrity(); if (tailStart_ != cachePtr_->cachedRange.first) { @@ -730,12 +726,14 @@ class IOBufQueue { } // For WritableRangeCache move assignment/construction. - void updateCacheRef(WritableRangeCacheData& newRef) { cachePtr_ = &newRef; } + void updateCacheRef(WritableRangeCacheData& newRef) noexcept { + cachePtr_ = &newRef; + } /** * Update cached writable tail range. Called by updateGuard() */ - void updateWritableTailCache() { + void updateWritableTailCache() noexcept { if (FOLLY_LIKELY(head_ != nullptr)) { IOBuf* buf = head_->prev(); if (FOLLY_LIKELY(!buf->isSharedOne())) {