Summary:
The compiler is able to make some nice optimizations when it
knows that move constructors are noexcept. (In particular, it helps a
lot inside of std::vector if you don't need to worry about the
possibility of exception during reallocation.) Some move constructors in
folly are obviously moveable: change them.
Test Plan: unit tests
Reviewed By: delong.j@fb.com
Subscribers: trunkagent, sdwilsh, njormrod, folly-diffs@
FB internal diff:
D1644296
Tasks:
5486739
Signature: t1:
1644296:
1414618605:
d9a0db5193c82650b96e9c62b019d5da218b15c5
}
BenchmarkSuspender(const BenchmarkSuspender &) = delete;
- BenchmarkSuspender(BenchmarkSuspender && rhs) {
+ BenchmarkSuspender(BenchmarkSuspender && rhs) noexcept {
start = rhs.start;
rhs.start.tv_nsec = rhs.start.tv_sec = 0;
}
ownsFd_ = true;
}
-File::File(File&& other)
+File::File(File&& other) noexcept
: fd_(other.fd_)
, ownsFd_(other.ownsFd_) {
other.release();
return File(fd, true);
}
-int File::release() {
+int File::release() noexcept {
int released = fd_;
fd_ = -1;
ownsFd_ = false;
* Returns and releases the file descriptor; no longer owned by this File.
* Returns -1 if the File object didn't wrap a file.
*/
- int release();
+ int release() noexcept;
/**
* Swap this File with another.
void swap(File& other);
// movable
- File(File&&);
+ File(File&&) noexcept;
File& operator=(File&&);
// FLOCK (INTERPROCESS) LOCKS
namespace folly {
-MemoryMapping::MemoryMapping(MemoryMapping&& other) {
+MemoryMapping::MemoryMapping(MemoryMapping&& other) noexcept {
swap(other);
}
return *this;
}
-void MemoryMapping::swap(MemoryMapping& other) {
+void MemoryMapping::swap(MemoryMapping& other) noexcept {
using std::swap;
swap(this->file_, other.file_);
swap(this->mapStart_, other.mapStart_);
swap(this->data_, other.data_);
}
-void swap(MemoryMapping& a, MemoryMapping& b) { a.swap(b); }
+void swap(MemoryMapping& a, MemoryMapping& b) noexcept { a.swap(b); }
void alignedForwardMemcpy(void* dst, const void* src, size_t size) {
assert(reinterpret_cast<uintptr_t>(src) % alignof(unsigned long) == 0);
off_t length=-1,
Options options=Options());
- MemoryMapping(MemoryMapping&&);
+ MemoryMapping(MemoryMapping&&) noexcept;
~MemoryMapping();
MemoryMapping& operator=(MemoryMapping);
- void swap(MemoryMapping& other);
+ void swap(MemoryMapping& other) noexcept;
/**
* Lock the pages in memory
MutableByteRange data_;
};
-void swap(MemoryMapping&, MemoryMapping&);
+void swap(MemoryMapping&, MemoryMapping&) noexcept;
/**
* A special case of memcpy() that always copies memory forwards.
ScopeGuardImplBase()
: dismissed_(false) {}
- ScopeGuardImplBase(ScopeGuardImplBase&& other)
+ ScopeGuardImplBase(ScopeGuardImplBase&& other) noexcept
: dismissed_(other.dismissed_) {
other.dismissed_ = true;
}
public:
ThreadLocalPtr() : id_(threadlocal_detail::StaticMeta<Tag>::create()) { }
- ThreadLocalPtr(ThreadLocalPtr&& other) : id_(other.id_) {
+ ThreadLocalPtr(ThreadLocalPtr&& other) noexcept : id_(other.id_) {
other.id_ = 0;
}
chainLength_(0) {
}
-IOBufQueue::IOBufQueue(IOBufQueue&& other)
+IOBufQueue::IOBufQueue(IOBufQueue&& other) noexcept
: options_(other.options_),
chainLength_(other.chainLength_),
head_(std::move(other.head_)) {
void clear();
/** Movable */
- IOBufQueue(IOBufQueue&&);
+ IOBufQueue(IOBufQueue&&) noexcept;
IOBufQueue& operator=(IOBufQueue&&);
private:
}
struct GuardObjBase {
- GuardObjBase(GuardObjBase&&) {}
+ GuardObjBase(GuardObjBase&&) noexcept {}
GuardObjBase() {}
GuardObjBase(GuardObjBase const&) = delete;
GuardObjBase& operator=(GuardObjBase const&) = delete;
struct Mover {
Mover() {}
- Mover(Mover&&) {}
+ Mover(Mover&&) noexcept {}
Mover(const Mover&) = delete;
Mover& operator=(const Mover&) = delete;
};
struct CopyCount {
CopyCount() {}
CopyCount(const CopyCount&) { ++count; }
- CopyCount(CopyCount&&) {}
+ CopyCount(CopyCount&&) noexcept {}
static int count;
~NoncopyableCounter() {
--alive;
}
- NoncopyableCounter(NoncopyableCounter&&) { ++alive; }
+ NoncopyableCounter(NoncopyableCounter&&) noexcept { ++alive; }
NoncopyableCounter(NoncopyableCounter const&) = delete;
NoncopyableCounter& operator=(NoncopyableCounter const&) const = delete;
NoncopyableCounter& operator=(NoncopyableCounter&&) { return *this; }