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 { ...@@ -116,7 +116,7 @@ struct BenchmarkSuspender {
} }
BenchmarkSuspender(const BenchmarkSuspender &) = delete; BenchmarkSuspender(const BenchmarkSuspender &) = delete;
BenchmarkSuspender(BenchmarkSuspender && rhs) { BenchmarkSuspender(BenchmarkSuspender && rhs) noexcept {
start = rhs.start; start = rhs.start;
rhs.start.tv_nsec = rhs.start.tv_sec = 0; rhs.start.tv_nsec = rhs.start.tv_sec = 0;
} }
......
...@@ -52,7 +52,7 @@ File::File(const char* name, int flags, mode_t mode) ...@@ -52,7 +52,7 @@ File::File(const char* name, int flags, mode_t mode)
ownsFd_ = true; ownsFd_ = true;
} }
File::File(File&& other) File::File(File&& other) noexcept
: fd_(other.fd_) : fd_(other.fd_)
, ownsFd_(other.ownsFd_) { , ownsFd_(other.ownsFd_) {
other.release(); other.release();
...@@ -80,7 +80,7 @@ File::~File() { ...@@ -80,7 +80,7 @@ File::~File() {
return File(fd, true); return File(fd, true);
} }
int File::release() { int File::release() noexcept {
int released = fd_; int released = fd_;
fd_ = -1; fd_ = -1;
ownsFd_ = false; ownsFd_ = false;
......
...@@ -87,7 +87,7 @@ class File { ...@@ -87,7 +87,7 @@ class File {
* Returns and releases the file descriptor; no longer owned by this File. * Returns and releases the file descriptor; no longer owned by this File.
* Returns -1 if the File object didn't wrap a file. * Returns -1 if the File object didn't wrap a file.
*/ */
int release(); int release() noexcept;
/** /**
* Swap this File with another. * Swap this File with another.
...@@ -95,7 +95,7 @@ class File { ...@@ -95,7 +95,7 @@ class File {
void swap(File& other); void swap(File& other);
// movable // movable
File(File&&); File(File&&) noexcept;
File& operator=(File&&); File& operator=(File&&);
// FLOCK (INTERPROCESS) LOCKS // FLOCK (INTERPROCESS) LOCKS
......
...@@ -38,7 +38,7 @@ DEFINE_int64(mlock_chunk_size, 1 << 20, // 1MB ...@@ -38,7 +38,7 @@ DEFINE_int64(mlock_chunk_size, 1 << 20, // 1MB
namespace folly { namespace folly {
MemoryMapping::MemoryMapping(MemoryMapping&& other) { MemoryMapping::MemoryMapping(MemoryMapping&& other) noexcept {
swap(other); swap(other);
} }
...@@ -298,7 +298,7 @@ MemoryMapping& MemoryMapping::operator=(MemoryMapping other) { ...@@ -298,7 +298,7 @@ MemoryMapping& MemoryMapping::operator=(MemoryMapping other) {
return *this; return *this;
} }
void MemoryMapping::swap(MemoryMapping& other) { void MemoryMapping::swap(MemoryMapping& other) noexcept {
using std::swap; using std::swap;
swap(this->file_, other.file_); swap(this->file_, other.file_);
swap(this->mapStart_, other.mapStart_); swap(this->mapStart_, other.mapStart_);
...@@ -308,7 +308,7 @@ void MemoryMapping::swap(MemoryMapping& other) { ...@@ -308,7 +308,7 @@ void MemoryMapping::swap(MemoryMapping& other) {
swap(this->data_, other.data_); 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) { void alignedForwardMemcpy(void* dst, const void* src, size_t size) {
assert(reinterpret_cast<uintptr_t>(src) % alignof(unsigned long) == 0); assert(reinterpret_cast<uintptr_t>(src) % alignof(unsigned long) == 0);
......
...@@ -127,13 +127,13 @@ class MemoryMapping : boost::noncopyable { ...@@ -127,13 +127,13 @@ class MemoryMapping : boost::noncopyable {
off_t length=-1, off_t length=-1,
Options options=Options()); Options options=Options());
MemoryMapping(MemoryMapping&&); MemoryMapping(MemoryMapping&&) noexcept;
~MemoryMapping(); ~MemoryMapping();
MemoryMapping& operator=(MemoryMapping); MemoryMapping& operator=(MemoryMapping);
void swap(MemoryMapping& other); void swap(MemoryMapping& other) noexcept;
/** /**
* Lock the pages in memory * Lock the pages in memory
...@@ -229,7 +229,7 @@ class MemoryMapping : boost::noncopyable { ...@@ -229,7 +229,7 @@ class MemoryMapping : boost::noncopyable {
MutableByteRange data_; MutableByteRange data_;
}; };
void swap(MemoryMapping&, MemoryMapping&); void swap(MemoryMapping&, MemoryMapping&) noexcept;
/** /**
* A special case of memcpy() that always copies memory forwards. * A special case of memcpy() that always copies memory forwards.
......
...@@ -77,7 +77,7 @@ class ScopeGuardImplBase { ...@@ -77,7 +77,7 @@ class ScopeGuardImplBase {
ScopeGuardImplBase() ScopeGuardImplBase()
: dismissed_(false) {} : dismissed_(false) {}
ScopeGuardImplBase(ScopeGuardImplBase&& other) ScopeGuardImplBase(ScopeGuardImplBase&& other) noexcept
: dismissed_(other.dismissed_) { : dismissed_(other.dismissed_) {
other.dismissed_ = true; other.dismissed_ = true;
} }
......
...@@ -137,7 +137,7 @@ class ThreadLocalPtr { ...@@ -137,7 +137,7 @@ class ThreadLocalPtr {
public: public:
ThreadLocalPtr() : id_(threadlocal_detail::StaticMeta<Tag>::create()) { } ThreadLocalPtr() : id_(threadlocal_detail::StaticMeta<Tag>::create()) { }
ThreadLocalPtr(ThreadLocalPtr&& other) : id_(other.id_) { ThreadLocalPtr(ThreadLocalPtr&& other) noexcept : id_(other.id_) {
other.id_ = 0; other.id_ = 0;
} }
......
...@@ -71,7 +71,7 @@ IOBufQueue::IOBufQueue(const Options& options) ...@@ -71,7 +71,7 @@ IOBufQueue::IOBufQueue(const Options& options)
chainLength_(0) { chainLength_(0) {
} }
IOBufQueue::IOBufQueue(IOBufQueue&& other) IOBufQueue::IOBufQueue(IOBufQueue&& other) noexcept
: options_(other.options_), : options_(other.options_),
chainLength_(other.chainLength_), chainLength_(other.chainLength_),
head_(std::move(other.head_)) { head_(std::move(other.head_)) {
......
...@@ -262,7 +262,7 @@ class IOBufQueue { ...@@ -262,7 +262,7 @@ class IOBufQueue {
void clear(); void clear();
/** Movable */ /** Movable */
IOBufQueue(IOBufQueue&&); IOBufQueue(IOBufQueue&&) noexcept;
IOBufQueue& operator=(IOBufQueue&&); IOBufQueue& operator=(IOBufQueue&&);
private: private:
......
...@@ -73,7 +73,7 @@ std::function<void (int, int, double)> makeFunc() { ...@@ -73,7 +73,7 @@ std::function<void (int, int, double)> makeFunc() {
} }
struct GuardObjBase { struct GuardObjBase {
GuardObjBase(GuardObjBase&&) {} GuardObjBase(GuardObjBase&&) noexcept {}
GuardObjBase() {} GuardObjBase() {}
GuardObjBase(GuardObjBase const&) = delete; GuardObjBase(GuardObjBase const&) = delete;
GuardObjBase& operator=(GuardObjBase const&) = delete; GuardObjBase& operator=(GuardObjBase const&) = delete;
...@@ -115,7 +115,7 @@ guard(F&& f, Args&&... args) { ...@@ -115,7 +115,7 @@ guard(F&& f, Args&&... args) {
struct Mover { struct Mover {
Mover() {} Mover() {}
Mover(Mover&&) {} Mover(Mover&&) noexcept {}
Mover(const Mover&) = delete; Mover(const Mover&) = delete;
Mover& operator=(const Mover&) = delete; Mover& operator=(const Mover&) = delete;
}; };
......
...@@ -72,7 +72,7 @@ TEST(Lazy, Map) { ...@@ -72,7 +72,7 @@ TEST(Lazy, Map) {
struct CopyCount { struct CopyCount {
CopyCount() {} CopyCount() {}
CopyCount(const CopyCount&) { ++count; } CopyCount(const CopyCount&) { ++count; }
CopyCount(CopyCount&&) {} CopyCount(CopyCount&&) noexcept {}
static int count; static int count;
......
...@@ -136,7 +136,7 @@ struct NoncopyableCounter { ...@@ -136,7 +136,7 @@ struct NoncopyableCounter {
~NoncopyableCounter() { ~NoncopyableCounter() {
--alive; --alive;
} }
NoncopyableCounter(NoncopyableCounter&&) { ++alive; } NoncopyableCounter(NoncopyableCounter&&) noexcept { ++alive; }
NoncopyableCounter(NoncopyableCounter const&) = delete; NoncopyableCounter(NoncopyableCounter const&) = delete;
NoncopyableCounter& operator=(NoncopyableCounter const&) const = delete; NoncopyableCounter& operator=(NoncopyableCounter const&) const = delete;
NoncopyableCounter& operator=(NoncopyableCounter&&) { return *this; } 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