Make move operations noexcept

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1991
This commit is contained in:
Matej Ferencevic 2019-05-20 12:54:56 +02:00
parent ee2fa47b29
commit 3c48e612ef
12 changed files with 59 additions and 62 deletions

View File

@ -123,7 +123,7 @@ Value &Value::operator=(const Value &other) {
return *this;
}
Value::Value(Value &&other) : type_(other.type_) {
Value::Value(Value &&other) noexcept : type_(other.type_) {
switch (other.type_) {
case Type::Null:
break;
@ -164,7 +164,7 @@ Value::Value(Value &&other) : type_(other.type_) {
other.type_ = Type::Null;
}
Value &Value::operator=(Value &&other) {
Value &Value::operator=(Value &&other) noexcept {
if (this != &other) {
this->~Value();
// set the type of this
@ -380,4 +380,4 @@ std::ostream &operator<<(std::ostream &os, const Value::Type type) {
return os << "path";
}
}
}
} // namespace communication::bolt

View File

@ -166,32 +166,32 @@ class Value {
Value(const Path &value) : type_(Type::Path) { new (&path_v) Path(value); }
// move constructors for non-primitive values
Value(std::string &&value) : type_(Type::String) {
Value(std::string &&value) noexcept : type_(Type::String) {
new (&string_v) std::string(std::move(value));
}
Value(std::vector<Value> &&value) : type_(Type::List) {
Value(std::vector<Value> &&value) noexcept : type_(Type::List) {
new (&list_v) std::vector<Value>(std::move(value));
}
Value(std::map<std::string, Value> &&value) : type_(Type::Map) {
Value(std::map<std::string, Value> &&value) noexcept : type_(Type::Map) {
new (&map_v) std::map<std::string, Value>(std::move(value));
}
Value(Vertex &&value) : type_(Type::Vertex) {
Value(Vertex &&value) noexcept : type_(Type::Vertex) {
new (&vertex_v) Vertex(std::move(value));
}
Value(Edge &&value) : type_(Type::Edge) {
Value(Edge &&value) noexcept : type_(Type::Edge) {
new (&edge_v) Edge(std::move(value));
}
Value(UnboundedEdge &&value) : type_(Type::UnboundedEdge) {
Value(UnboundedEdge &&value) noexcept : type_(Type::UnboundedEdge) {
new (&unbounded_edge_v) UnboundedEdge(std::move(value));
}
Value(Path &&value) : type_(Type::Path) {
Value(Path &&value) noexcept : type_(Type::Path) {
new (&path_v) Path(std::move(value));
}
Value &operator=(const Value &other);
Value &operator=(Value &&other);
Value &operator=(Value &&other) noexcept;
Value(const Value &other);
Value(Value &&other);
Value(Value &&other) noexcept;
~Value();
Type type() const { return type_; }

View File

@ -470,7 +470,7 @@ class SkipList : private utils::Lockable<lock_t> {
Accessor(const Accessor &) = delete;
// cppcheck-suppress uninitMemberVar
Accessor(Accessor &&other)
Accessor(Accessor &&other) noexcept
: skiplist(other.skiplist), status_(other.status_) {
other.skiplist = nullptr;
}

View File

@ -73,15 +73,7 @@ class SkipListGC {
* ones are alive and which ones are dead.
*/
struct AccessorStatus {
AccessorStatus(const int64_t id, bool alive) : id_(id), alive_(alive) {}
AccessorStatus(AccessorStatus &&other) = default;
AccessorStatus(const AccessorStatus &other) = delete;
AccessorStatus operator=(const AccessorStatus &other) = delete;
AccessorStatus operator=(AccessorStatus &&other) = delete;
const int64_t id_{-1};
int64_t id_{-1};
bool alive_{false};
};
@ -91,7 +83,7 @@ class SkipListGC {
*/
AccessorStatus &CreateNewAccessor() {
std::unique_lock<std::mutex> lock(mutex_);
accessors_.emplace_back(++last_accessor_id_, true);
accessors_.push_back({++last_accessor_id_, true});
return accessors_.back();
}

View File

@ -32,7 +32,7 @@ GraphDbAccessor::GraphDbAccessor(GraphDb *db,
transaction_(db->tx_engine().BeginBlocking(parent_tx)),
transaction_starter_{true} {}
GraphDbAccessor::GraphDbAccessor(GraphDbAccessor &&other)
GraphDbAccessor::GraphDbAccessor(GraphDbAccessor &&other) noexcept
: db_(other.db_),
transaction_(other.transaction_),
transaction_starter_(other.transaction_starter_),
@ -43,7 +43,7 @@ GraphDbAccessor::GraphDbAccessor(GraphDbAccessor &&other)
other.transaction_starter_ = false;
}
GraphDbAccessor &GraphDbAccessor::operator=(GraphDbAccessor &&other) {
GraphDbAccessor &GraphDbAccessor::operator=(GraphDbAccessor &&other) noexcept {
db_ = other.db_;
transaction_ = other.transaction_;
transaction_starter_ = other.transaction_starter_;

View File

@ -54,8 +54,8 @@ class GraphDbAccessor {
GraphDbAccessor(const GraphDbAccessor &other) = delete;
GraphDbAccessor &operator=(const GraphDbAccessor &other) = delete;
GraphDbAccessor(GraphDbAccessor &&other);
GraphDbAccessor &operator=(GraphDbAccessor &&other);
GraphDbAccessor(GraphDbAccessor &&other) noexcept;
GraphDbAccessor &operator=(GraphDbAccessor &&other) noexcept;
/**
* Creates a new Vertex and returns an accessor to it. If the ID is

View File

@ -51,7 +51,7 @@ TypedValue::TypedValue(const PropertyValue &value) {
LOG(FATAL) << "Unsupported type";
}
TypedValue::TypedValue(PropertyValue &&value) {
TypedValue::TypedValue(PropertyValue &&value) noexcept {
switch (value.type()) {
case PropertyValue::Type::Null:
type_ = Type::Null;
@ -128,7 +128,7 @@ TypedValue::TypedValue(const TypedValue &other) : type_(other.type_) {
LOG(FATAL) << "Unsupported TypedValue::Type";
}
TypedValue::TypedValue(TypedValue &&other) : type_(other.type_) {
TypedValue::TypedValue(TypedValue &&other) noexcept : type_(other.type_) {
switch (other.type_) {
case TypedValue::Type::Null:
break;
@ -335,7 +335,7 @@ DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(const Path &, Path, path_v)
#define DEFINE_TYPED_VALUE_MOVE_ASSIGNMENT(type_param, typed_value_type, \
member) \
TypedValue &TypedValue::operator=(type_param &&other) { \
TypedValue &TypedValue::operator=(type_param &&other) noexcept { \
if (this->type_ == TypedValue::Type::typed_value_type) { \
this->member = std::move(other); \
} else { \
@ -395,7 +395,7 @@ TypedValue &TypedValue::operator=(const TypedValue &other) {
return *this;
}
TypedValue &TypedValue::operator=(TypedValue &&other) {
TypedValue &TypedValue::operator=(TypedValue &&other) noexcept {
if (this != &other) {
DestroyValue();
type_ = other.type_;

View File

@ -78,7 +78,7 @@ class TypedValue {
static const TypedValue Null;
TypedValue(const TypedValue &other);
TypedValue(TypedValue &&other);
TypedValue(TypedValue &&other) noexcept;
// constructors for primitive types
TypedValue(bool value) : type_(Type::Bool) { bool_v = value; }
@ -113,25 +113,26 @@ class TypedValue {
TypedValue(const PropertyValue &value);
// move constructors for non-primitive types
TypedValue(std::string &&value) : type_(Type::String) {
TypedValue(std::string &&value) noexcept : type_(Type::String) {
new (&string_v) std::string(std::move(value));
}
TypedValue(std::vector<TypedValue> &&value) : type_(Type::List) {
TypedValue(std::vector<TypedValue> &&value) noexcept : type_(Type::List) {
new (&list_v) std::vector<TypedValue>(std::move(value));
}
TypedValue(std::map<std::string, TypedValue> &&value) : type_(Type::Map) {
TypedValue(std::map<std::string, TypedValue> &&value) noexcept
: type_(Type::Map) {
new (&map_v) std::map<std::string, TypedValue>(std::move(value));
}
TypedValue(VertexAccessor &&vertex) : type_(Type::Vertex) {
TypedValue(VertexAccessor &&vertex) noexcept : type_(Type::Vertex) {
new (&vertex_v) VertexAccessor(std::move(vertex));
}
TypedValue(EdgeAccessor &&edge) : type_(Type::Edge) {
TypedValue(EdgeAccessor &&edge) noexcept : type_(Type::Edge) {
new (&edge_v) EdgeAccessor(std::move(edge));
}
TypedValue(Path &&path) : type_(Type::Path) {
TypedValue(Path &&path) noexcept : type_(Type::Path) {
new (&path_v) Path(std::move(path));
}
TypedValue(PropertyValue &&value);
TypedValue(PropertyValue &&value) noexcept;
// copy assignment operators
TypedValue &operator=(const char *);
@ -148,13 +149,13 @@ class TypedValue {
TypedValue &operator=(const TypedValue &);
// move assignment operators
TypedValue &operator=(std::string &&);
TypedValue &operator=(std::vector<TypedValue> &&);
TypedValue &operator=(TypedValue::value_map_t &&);
TypedValue &operator=(VertexAccessor &&);
TypedValue &operator=(EdgeAccessor &&);
TypedValue &operator=(Path &&);
TypedValue &operator=(TypedValue &&);
TypedValue &operator=(std::string &&) noexcept;
TypedValue &operator=(std::vector<TypedValue> &&) noexcept;
TypedValue &operator=(TypedValue::value_map_t &&) noexcept;
TypedValue &operator=(VertexAccessor &&) noexcept;
TypedValue &operator=(EdgeAccessor &&) noexcept;
TypedValue &operator=(Path &&) noexcept;
TypedValue &operator=(TypedValue &&) noexcept;
~TypedValue();

View File

@ -127,7 +127,8 @@ PropertyValue::PropertyValue(const PropertyValue &other) : type_(other.type_) {
}
}
PropertyValue::PropertyValue(PropertyValue &&other) : type_(other.type_) {
PropertyValue::PropertyValue(PropertyValue &&other) noexcept
: type_(other.type_) {
switch (other.type_) {
case Type::Null:
return;
@ -183,7 +184,7 @@ PropertyValue &PropertyValue::operator=(const PropertyValue &other) {
return *this;
}
PropertyValue &PropertyValue::operator=(PropertyValue &&other) {
PropertyValue &PropertyValue::operator=(PropertyValue &&other) noexcept {
if (this != &other) {
DestroyValue();
type_ = other.type_;

View File

@ -56,22 +56,23 @@ class PropertyValue {
}
// move constructors for non-primitive types
PropertyValue(std::string &&value) : type_(Type::String) {
PropertyValue(std::string &&value) noexcept : type_(Type::String) {
new (&string_v) std::string(std::move(value));
}
PropertyValue(std::vector<PropertyValue> &&value) : type_(Type::List) {
PropertyValue(std::vector<PropertyValue> &&value) noexcept
: type_(Type::List) {
new (&list_v) std::vector<PropertyValue>(std::move(value));
}
PropertyValue(std::map<std::string, PropertyValue> &&value)
PropertyValue(std::map<std::string, PropertyValue> &&value) noexcept
: type_(Type::Map) {
new (&map_v) std::map<std::string, PropertyValue>(std::move(value));
}
PropertyValue &operator=(const PropertyValue &other);
PropertyValue &operator=(PropertyValue &&other);
PropertyValue &operator=(PropertyValue &&other) noexcept;
PropertyValue(const PropertyValue &other);
PropertyValue(PropertyValue &&other);
PropertyValue(PropertyValue &&other) noexcept;
~PropertyValue();
Type type() const { return type_; }

View File

@ -71,7 +71,7 @@ struct SkipListNode {
SkipListNode(const TObj &_obj, uint8_t _height)
: obj(_obj), height(_height) {}
SkipListNode(TObj &&_obj, uint8_t _height)
SkipListNode(TObj &&_obj, uint8_t _height) noexcept
: obj(std::move(_obj)), height(_height) {}
// The items here are carefully placed to minimize padding gaps.
@ -540,14 +540,15 @@ class SkipList final {
Accessor(const Accessor &other)
: skiplist_(other.skiplist_), id_(skiplist_->gc_.AllocateId()) {}
Accessor(Accessor &&other) : skiplist_(other.skiplist_), id_(other.id_) {
Accessor(Accessor &&other) noexcept
: skiplist_(other.skiplist_), id_(other.id_) {
other.skiplist_ = nullptr;
}
Accessor &operator=(const Accessor &other) {
skiplist_ = other.skiplist_;
id_ = skiplist_->gc_.AllocateId();
}
Accessor &operator=(Accessor &&other) {
Accessor &operator=(Accessor &&other) noexcept {
skiplist_ = other.skiplist_;
id_ = other.id_;
other.skiplist_ = nullptr;
@ -680,7 +681,7 @@ class SkipList final {
ConstAccessor(const ConstAccessor &other)
: skiplist_(other.skiplist_), id_(skiplist_->gc_.AllocateId()) {}
ConstAccessor(ConstAccessor &&other)
ConstAccessor(ConstAccessor &&other) noexcept
: skiplist_(other.skiplist_), id_(other.id_) {
other.skiplist_ = nullptr;
}
@ -688,7 +689,7 @@ class SkipList final {
skiplist_ = other.skiplist_;
id_ = skiplist_->gc_.AllocateId();
}
ConstAccessor &operator=(ConstAccessor &&other) {
ConstAccessor &operator=(ConstAccessor &&other) noexcept {
skiplist_ = other.skiplist_;
id_ = other.id_;
other.skiplist_ = nullptr;
@ -757,10 +758,11 @@ class SkipList final {
SkipListNode<TObj>(kSkipListMaxHeight);
}
SkipList(SkipList &&other) : head_(other.head_), size_(other.size_.load()) {
SkipList(SkipList &&other) noexcept
: head_(other.head_), size_(other.size_.load()) {
other.head_ = nullptr;
}
SkipList &operator=(SkipList &&other) {
SkipList &operator=(SkipList &&other) noexcept {
TNode *head = head_;
while (head != nullptr) {
TNode *succ = head->nexts[0].load(std::memory_order_relaxed);

View File

@ -46,8 +46,8 @@ class Stack {
"the size of Stack::Block is a multiple of the page size.");
}
Stack(Stack &&other) : head_(other.head_) { other.head_ = nullptr; }
Stack &operator=(Stack &&other) {
Stack(Stack &&other) noexcept : head_(other.head_) { other.head_ = nullptr; }
Stack &operator=(Stack &&other) noexcept {
while (head_ != nullptr) {
Block *prev = head_->prev;
delete head_;