Commit 75c6adfa authored by Nicholas Ormrod's avatar Nicholas Ormrod Committed by Pavlo Kushnir

Move constructors should be noexcept

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
parent 449e2596
......@@ -116,7 +116,7 @@ struct BenchmarkSuspender {
}
BenchmarkSuspender(const BenchmarkSuspender &) = delete;
BenchmarkSuspender(BenchmarkSuspender && rhs) {
BenchmarkSuspender(BenchmarkSuspender && rhs) noexcept {
start = rhs.start;
rhs.start.tv_nsec = rhs.start.tv_sec = 0;
}
......
......@@ -52,7 +52,7 @@ File::File(const char* name, int flags, mode_t mode)
ownsFd_ = true;
}
File::File(File&& other)
File::File(File&& other) noexcept
: fd_(other.fd_)
, ownsFd_(other.ownsFd_) {
other.release();
......@@ -80,7 +80,7 @@ File::~File() {
return File(fd, true);
}
int File::release() {
int File::release() noexcept {
int released = fd_;
fd_ = -1;
ownsFd_ = false;
......
......@@ -87,7 +87,7 @@ class File {
* 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.
......@@ -95,7 +95,7 @@ class File {
void swap(File& other);
// movable
File(File&&);
File(File&&) noexcept;
File& operator=(File&&);
// FLOCK (INTERPROCESS) LOCKS
......
......@@ -38,7 +38,7 @@ DEFINE_int64(mlock_chunk_size, 1 << 20, // 1MB
namespace folly {
MemoryMapping::MemoryMapping(MemoryMapping&& other) {
MemoryMapping::MemoryMapping(MemoryMapping&& other) noexcept {
swap(other);
}
......@@ -298,7 +298,7 @@ MemoryMapping& MemoryMapping::operator=(MemoryMapping 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_);
......@@ -308,7 +308,7 @@ void MemoryMapping::swap(MemoryMapping& other) {
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);
......
......@@ -127,13 +127,13 @@ class MemoryMapping : boost::noncopyable {
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
......@@ -229,7 +229,7 @@ class MemoryMapping : boost::noncopyable {
MutableByteRange data_;
};
void swap(MemoryMapping&, MemoryMapping&);
void swap(MemoryMapping&, MemoryMapping&) noexcept;
/**
* A special case of memcpy() that always copies memory forwards.
......
......@@ -77,7 +77,7 @@ class ScopeGuardImplBase {
ScopeGuardImplBase()
: dismissed_(false) {}
ScopeGuardImplBase(ScopeGuardImplBase&& other)
ScopeGuardImplBase(ScopeGuardImplBase&& other) noexcept
: dismissed_(other.dismissed_) {
other.dismissed_ = true;
}
......
......@@ -137,7 +137,7 @@ class ThreadLocalPtr {
public:
ThreadLocalPtr() : id_(threadlocal_detail::StaticMeta<Tag>::create()) { }
ThreadLocalPtr(ThreadLocalPtr&& other) : id_(other.id_) {
ThreadLocalPtr(ThreadLocalPtr&& other) noexcept : id_(other.id_) {
other.id_ = 0;
}
......
......@@ -71,7 +71,7 @@ IOBufQueue::IOBufQueue(const Options& options)
chainLength_(0) {
}
IOBufQueue::IOBufQueue(IOBufQueue&& other)
IOBufQueue::IOBufQueue(IOBufQueue&& other) noexcept
: options_(other.options_),
chainLength_(other.chainLength_),
head_(std::move(other.head_)) {
......
......@@ -262,7 +262,7 @@ class IOBufQueue {
void clear();
/** Movable */
IOBufQueue(IOBufQueue&&);
IOBufQueue(IOBufQueue&&) noexcept;
IOBufQueue& operator=(IOBufQueue&&);
private:
......
......@@ -73,7 +73,7 @@ std::function<void (int, int, double)> makeFunc() {
}
struct GuardObjBase {
GuardObjBase(GuardObjBase&&) {}
GuardObjBase(GuardObjBase&&) noexcept {}
GuardObjBase() {}
GuardObjBase(GuardObjBase const&) = delete;
GuardObjBase& operator=(GuardObjBase const&) = delete;
......@@ -115,7 +115,7 @@ guard(F&& f, Args&&... args) {
struct Mover {
Mover() {}
Mover(Mover&&) {}
Mover(Mover&&) noexcept {}
Mover(const Mover&) = delete;
Mover& operator=(const Mover&) = delete;
};
......
......@@ -72,7 +72,7 @@ TEST(Lazy, Map) {
struct CopyCount {
CopyCount() {}
CopyCount(const CopyCount&) { ++count; }
CopyCount(CopyCount&&) {}
CopyCount(CopyCount&&) noexcept {}
static int count;
......
......@@ -136,7 +136,7 @@ struct NoncopyableCounter {
~NoncopyableCounter() {
--alive;
}
NoncopyableCounter(NoncopyableCounter&&) { ++alive; }
NoncopyableCounter(NoncopyableCounter&&) noexcept { ++alive; }
NoncopyableCounter(NoncopyableCounter const&) = delete;
NoncopyableCounter& operator=(NoncopyableCounter const&) const = delete;
NoncopyableCounter& operator=(NoncopyableCounter&&) { return *this; }
......
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